fix(播放器): 修复音频播放问题和缓存列表

1.添加o65音频控制播放/暂停事件处理
2.修复播放前延迟问题,优化播放流程
3.优化临时内容清理逻辑,使用串行删除代替并行
This commit is contained in:
SarmonFish
2026-03-08 12:29:57 +08:00
parent 998dcf62e4
commit 782b1f3671
3 changed files with 73 additions and 19 deletions
@@ -87,17 +87,18 @@ export default {
if (this.clearControl.sc) {
const contents = await global.savedcontent.SavedContentManager.listAllContent()
contents.forEach((ct) => {
tasks.push(global.savedcontent.SavedContentManager.deleteContent(ct.id))
})
for (const ct of contents) {
await global.savedcontent.SavedContentManager.deleteContent(ct.id)
}
}
if (this.clearControl.videoAudio) {
const contents = await global.savedcontent.SavedContentManager.listAllContent()
const videoAudioContents = contents.filter((ct) => ct.type === 'videoAudio')
videoAudioContents.forEach((ct) => {
tasks.push(global.savedcontent.SavedContentManager.deleteContent(ct.id))
})
for (let i = 0; i < videoAudioContents.length; i++) {
const ct = videoAudioContents[i]
await global.savedcontent.SavedContentManager.deleteContent(ct.id)
}
}
await Promise.all(tasks)
+65 -12
View File
@@ -257,6 +257,25 @@
audio.pause();
}
};
audio.onctrlplay = () => {
if (!this.playerState.isPlaying) {
this.playerState.isPlaying = true;
this.isPlaying = true;
if (this.playTimeoutId) {
clearTimeout(this.playTimeoutId);
this.playTimeoutId = null;
}
audio.play();
this.pendingSongId = null;
}
};
audio.onctrlpause = () => {
if (this.playerState.isPlaying) {
this.playerState.isPlaying = false;
this.isPlaying = false;
audio.pause();
}
};
audio.onstop = () => {
this.playerState.isPlaying = false;
this.isPlaying = false;
@@ -690,11 +709,26 @@
audio.src = that.currSong.url;
setTimeout(function() {
if (!that.audioReady && that.isPlaying !== true) {
that.duration = audio.duration || 0;
that.audioReady = true;
that.isPlaying = true;
that.playerState.isPlaying = true;
audio.play();
const dur = audio.duration;
if (dur && dur > 0 && !isNaN(dur)) {
that.duration = dur;
that.audioReady = true;
that.isPlaying = true;
that.playerState.isPlaying = true;
audio.play();
} else {
console.log('音频时长无效,等待重试');
setTimeout(function() {
if (!that.audioReady && that.isPlaying !== true) {
const dur2 = audio.duration;
that.duration = dur2 || 0;
that.audioReady = true;
that.isPlaying = true;
that.playerState.isPlaying = true;
audio.play();
}
}, 500);
}
}
}, 500);
} else {
@@ -721,11 +755,26 @@
audio.src = that.currSong.url;
setTimeout(function() {
if (!that.audioReady && that.isPlaying !== true) {
that.duration = audio.duration || 0;
that.audioReady = true;
that.isPlaying = true;
that.playerState.isPlaying = true;
audio.play();
const dur = audio.duration;
if (dur && dur > 0 && !isNaN(dur)) {
that.duration = dur;
that.audioReady = true;
that.isPlaying = true;
that.playerState.isPlaying = true;
audio.play();
} else {
console.log('视频音频时长无效,等待重试');
setTimeout(function() {
if (!that.audioReady && that.isPlaying !== true) {
const dur2 = audio.duration;
that.duration = dur2 || 0;
that.audioReady = true;
that.isPlaying = true;
that.playerState.isPlaying = true;
audio.play();
}
}, 500);
}
}
}, 500);
return;
@@ -936,7 +985,9 @@
that.toastLog('校验成功,准备播放');
that.currSong.url = result.uri;
that.saveVideoAudioToSavedContent(result.uri);
that.playCurrentSong();
setTimeout(() => {
that.playCurrentSong();
}, 300);
}).catch((error) => {
that.toastLog('校验异常,回退直链');
that.currSong.url = audioUrl;
@@ -992,7 +1043,9 @@
}
that.currSong.url = result.uri;
that.saveVideoAudioToSavedContent(result.uri);
that.playCurrentSong();
setTimeout(() => {
that.playCurrentSong();
}, 300);
}).catch((error) => {
that.toastLog('校验异常,回退直链');
that.currSong.url = audioUrl;
+1 -1
View File
@@ -128,7 +128,7 @@ export class SavedContentManager {
// 读取所有存储内容的 id 和 title 列表
static async listAllContent(): Promise<any> {
return storageIndex;
return [...storageIndex];
}
// 删除内容