feat: 优化UI
This commit is contained in:
+8
-11
@@ -10,6 +10,7 @@ const api = require('./api')
|
||||
let bgAudioManager = null
|
||||
let appInstance = null
|
||||
let _switching = false // 切换音频时的锁,防止 onStop 事件干扰
|
||||
let _ended = false // 标记音频是否已自然播放完毕
|
||||
|
||||
/**
|
||||
* 初始化音频管理器
|
||||
@@ -42,6 +43,7 @@ function init(app) {
|
||||
})
|
||||
|
||||
bgAudioManager.onEnded(() => {
|
||||
_ended = true
|
||||
reportHistory()
|
||||
updatePlayState(false)
|
||||
appInstance.globalData.currentTime = appInstance.globalData.duration
|
||||
@@ -140,6 +142,7 @@ function playContent(content) {
|
||||
|
||||
// 标记正在切换,防止旧音频的 onStop 干扰
|
||||
_switching = true
|
||||
_ended = false // 重置结束标记
|
||||
|
||||
appInstance.globalData.activeContent = content
|
||||
appInstance.globalData.currentTime = 0
|
||||
@@ -167,18 +170,12 @@ function togglePlay() {
|
||||
if (appInstance.globalData.isPlaying) {
|
||||
bgAudioManager.pause()
|
||||
} else {
|
||||
// 检查 bgAudioManager 是否还有有效的 src
|
||||
// 音频结束/被系统回收后,src 会变为空,此时 play() 无效
|
||||
// 需要重新设置 src 来恢复播放
|
||||
var currentSrc = ''
|
||||
try {
|
||||
currentSrc = bgAudioManager.src
|
||||
} catch (e) {
|
||||
currentSrc = ''
|
||||
}
|
||||
// 音频已自然播放完毕,或 src 被系统回收 → 从头重新播放
|
||||
var srcEmpty = false
|
||||
try { srcEmpty = !bgAudioManager.src } catch (e) { srcEmpty = true }
|
||||
|
||||
if (!currentSrc) {
|
||||
// src 已被清空(音频结束、系统回收等),重新播放
|
||||
if (_ended || srcEmpty) {
|
||||
_ended = false
|
||||
playContent(appInstance.globalData.activeContent)
|
||||
} else {
|
||||
bgAudioManager.play()
|
||||
|
||||
Reference in New Issue
Block a user