mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-14 23:11:00 +08:00
- 新建 playbackController.ts,使用 generation-based 取消替代 playbackRequestManager 状态机 - audioService 重写:单一持久 HTMLAudioElement + Web Audio API,createMediaElementSource 只调一次 - playerCore 瘦身为纯状态管理,移除 handlePlayMusic/playAudio/checkPlaybackState - playlist next/prev 简化,区分用户手动切歌和歌曲自然播完 - MusicHook 适配 HTMLAudioElement API(.currentTime/.duration/.paused) - preloadService 从 Howl 实例缓存改为 URL 可用性验证 - 所有 view/component 调用者迁移到 playbackController.playTrack() 修复:快速切歌竞态、seek 到未缓冲位置失败、重启后自动播放循环提示、EQ 重建崩溃
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
/**
|
||
* 薄请求 ID 追踪器
|
||
* 用于 usePlayerHooks.ts 内部检查请求是否仍为最新。
|
||
* 实际的取消逻辑在 playbackController.ts 中(generation ID)。
|
||
*/
|
||
|
||
import type { SongResult } from '@/types/music';
|
||
|
||
class PlaybackRequestManager {
|
||
private currentRequestId: string | null = null;
|
||
private counter = 0;
|
||
|
||
/**
|
||
* 创建新请求,使之前的请求失效
|
||
*/
|
||
createRequest(song: SongResult): string {
|
||
const requestId = `req_${Date.now()}_${++this.counter}`;
|
||
this.currentRequestId = requestId;
|
||
console.log(`[RequestManager] 新请求: ${requestId}, 歌曲: ${song.name}`);
|
||
return requestId;
|
||
}
|
||
|
||
/**
|
||
* 检查请求是否仍为当前请求
|
||
*/
|
||
isRequestValid(requestId: string): boolean {
|
||
return this.currentRequestId === requestId;
|
||
}
|
||
|
||
/**
|
||
* 激活请求(兼容旧调用,直接返回 isRequestValid 结果)
|
||
*/
|
||
activateRequest(requestId: string): boolean {
|
||
return this.isRequestValid(requestId);
|
||
}
|
||
|
||
/**
|
||
* 标记请求完成
|
||
*/
|
||
completeRequest(requestId: string): void {
|
||
console.log(`[RequestManager] 完成: ${requestId}`);
|
||
}
|
||
|
||
/**
|
||
* 标记请求失败
|
||
*/
|
||
failRequest(requestId: string): void {
|
||
console.log(`[RequestManager] 失败: ${requestId}`);
|
||
}
|
||
|
||
/**
|
||
* 获取当前请求ID
|
||
*/
|
||
getCurrentRequestId(): string | null {
|
||
return this.currentRequestId;
|
||
}
|
||
}
|
||
|
||
export const playbackRequestManager = new PlaybackRequestManager();
|