mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-07-01 13:17:33 +08:00
feat: 优化预加载逻辑和继续播放功能
This commit is contained in:
@@ -682,14 +682,19 @@ class AudioService {
|
||||
if (isHotSwap) {
|
||||
console.log('audioService: 执行无缝切换');
|
||||
|
||||
// 1. 获取当前播放进度
|
||||
let currentPos = 0;
|
||||
if (this.currentSound) {
|
||||
currentPos = this.currentSound.seek() as number;
|
||||
// 1. 获取当前播放进度或使用指定的 seekTime
|
||||
let targetPos = 0;
|
||||
if (seekTime > 0) {
|
||||
// 如果有指定的 seekTime(如恢复播放进度),优先使用
|
||||
targetPos = seekTime;
|
||||
console.log(`audioService: 使用指定的 seekTime: ${seekTime}s`);
|
||||
} else if (this.currentSound) {
|
||||
// 否则同步当前进度
|
||||
targetPos = this.currentSound.seek() as number;
|
||||
}
|
||||
|
||||
// 2. 同步新音频进度
|
||||
newSound.seek(currentPos);
|
||||
newSound.seek(targetPos);
|
||||
|
||||
// 3. 初始化新音频的 EQ
|
||||
await this.disposeEQ(true);
|
||||
@@ -711,7 +716,7 @@ class AudioService {
|
||||
this.currentTrack = track;
|
||||
this.pendingSound = null;
|
||||
|
||||
console.log(`audioService: 无缝切换完成,进度同步至 ${currentPos}s`);
|
||||
console.log(`audioService: 无缝切换完成,进度同步至 ${targetPos}s`);
|
||||
} else {
|
||||
// 普通加载逻辑
|
||||
await this.setupEQ(newSound);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理所有预加载资源
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user