feat: 优化预加载逻辑和继续播放功能

This commit is contained in:
alger
2025-12-17 15:05:40 +08:00
parent 6bc168c5bd
commit af9117ee5f
3 changed files with 46 additions and 10 deletions
+15
View File
@@ -113,6 +113,21 @@ class PreloadService {
return this.preloadedSounds.get(songId);
}
/**
* 消耗(使用)已预加载的音频
* 从缓存中移除但不 unload(由调用方管理生命周期)
* @returns 预加载的 Howl 实例,如果没有则返回 undefined
*/
public consume(songId: string | number): Howl | undefined {
const sound = this.preloadedSounds.get(songId);
if (sound) {
this.preloadedSounds.delete(songId);
console.log(`[PreloadService] 消耗预加载的歌曲: ${songId}`);
return sound;
}
return undefined;
}
/**
* 清理所有预加载资源
*/