|
@@ -62,6 +62,7 @@ export interface IPlayerService {
|
|
|
|
|
|
|
|
// 状态查询 - 兼容LocalMusic数据结构
|
|
// 状态查询 - 兼容LocalMusic数据结构
|
|
|
getCurrentState(): PlayerState;
|
|
getCurrentState(): PlayerState;
|
|
|
|
|
+ getActualPlayingState(): boolean;
|
|
|
getCurrentSong(): VideoItem | null;
|
|
getCurrentSong(): VideoItem | null;
|
|
|
getPlaylist(): VideoItem[];
|
|
getPlaylist(): VideoItem[];
|
|
|
getCurrentIndex(): number;
|
|
getCurrentIndex(): number;
|
|
@@ -119,6 +120,7 @@ export class UnifiedPlayerService implements IPlayerService, PlaylistSyncListene
|
|
|
private progressTimer: number = -1;
|
|
private progressTimer: number = -1;
|
|
|
private isInitialized: boolean = false;
|
|
private isInitialized: boolean = false;
|
|
|
private isDataRestored: boolean = false; // 新增:数据恢复完成标识
|
|
private isDataRestored: boolean = false; // 新增:数据恢复完成标识
|
|
|
|
|
+
|
|
|
private isPlayerPreparedForCurrentSong: boolean = false; // 新增:播放器是否已为当前歌曲准备就绪
|
|
private isPlayerPreparedForCurrentSong: boolean = false; // 新增:播放器是否已为当前歌曲准备就绪
|
|
|
private currentRetryCount: number = 0;
|
|
private currentRetryCount: number = 0;
|
|
|
private lastAvSessionUpdate: number = 0;
|
|
private lastAvSessionUpdate: number = 0;
|
|
@@ -682,6 +684,23 @@ async initialize(context: common.UIAbilityContext): Promise<void> {
|
|
|
return this.stateModel.getState();
|
|
return this.stateModel.getState();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取播放器实际播放状态(最准确)
|
|
|
|
|
+ * 直接从ijkPlayer获取,不依赖状态模型
|
|
|
|
|
+ */
|
|
|
|
|
+ getActualPlayingState(): boolean {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const ijkPlayer = this.playerManager?.getIjkPlayer();
|
|
|
|
|
+ if (ijkPlayer) {
|
|
|
|
|
+ return ijkPlayer.isPlaying();
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ LogUtils.getInstance().LOGI(`UnifiedPlayerService: Failed to get actual playing state: ${error}`);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
getCurrentSong(): VideoItem | null {
|
|
getCurrentSong(): VideoItem | null {
|
|
|
return this.playlistModel.getCurrentSong();
|
|
return this.playlistModel.getCurrentSong();
|
|
|
}
|
|
}
|
|
@@ -1655,7 +1674,7 @@ async initialize(context: common.UIAbilityContext): Promise<void> {
|
|
|
this.stateModel.updateSpeed(stateData.speed);
|
|
this.stateModel.updateSpeed(stateData.speed);
|
|
|
this.stateModel.updatePlayMode(stateData.playMode);
|
|
this.stateModel.updatePlayMode(stateData.playMode);
|
|
|
|
|
|
|
|
- // 恢复播放状态
|
|
|
|
|
|
|
+ // 恢复播放状态(UI会使用实际播放器状态,所以这里可以恢复逻辑状态)
|
|
|
this.stateModel.updatePlayingState(stateData.isPlaying || false);
|
|
this.stateModel.updatePlayingState(stateData.isPlaying || false);
|
|
|
|
|
|
|
|
// 恢复当前播放索引
|
|
// 恢复当前播放索引
|