|
@@ -484,6 +484,21 @@ export struct LocalMusic {
|
|
|
const currentState = this.unifiedPlayerService.getCurrentState();
|
|
const currentState = this.unifiedPlayerService.getCurrentState();
|
|
|
const actuallyPlaying = this.unifiedPlayerService.getActualPlayingState();
|
|
const actuallyPlaying = this.unifiedPlayerService.getActualPlayingState();
|
|
|
LogUtils.getInstance().LOGI(`Heanup LocalMusic: Syncing current state - StateModel: ${currentState.isPlaying}, ActualPlayer: ${actuallyPlaying}`);
|
|
LogUtils.getInstance().LOGI(`Heanup LocalMusic: Syncing current state - StateModel: ${currentState.isPlaying}, ActualPlayer: ${actuallyPlaying}`);
|
|
|
|
|
+
|
|
|
|
|
+ // 关键修复:如果播放器正在播放,立即同步UI状态和进度
|
|
|
|
|
+ if (actuallyPlaying) {
|
|
|
|
|
+ LogUtils.getInstance().LOGI('LocalMusic: Player is playing during init, syncing UI state');
|
|
|
|
|
+ this.setIsPlaying(true);
|
|
|
|
|
+ this.CONTROL_PlayStatus = PlayStatus.PLAY;
|
|
|
|
|
+ this.mDestroyPage = false;
|
|
|
|
|
+
|
|
|
|
|
+ // 立即启动进度定时器并更新一次进度
|
|
|
|
|
+ this.stopProgressTask();
|
|
|
|
|
+ this.startProgressTask();
|
|
|
|
|
+ this.setProgress(); // 立即更新一次UI
|
|
|
|
|
+
|
|
|
|
|
+ this.playChange(); // 更新播放状态UI
|
|
|
|
|
+ }
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
LogUtils.getInstance().LOGI(`Heanup LocalMusic: Failed to sync current state: ${error}`);
|
|
LogUtils.getInstance().LOGI(`Heanup LocalMusic: Failed to sync current state: ${error}`);
|
|
|
}
|
|
}
|
|
@@ -525,6 +540,17 @@ export struct LocalMusic {
|
|
|
this.songList = unifiedPlaylist;
|
|
this.songList = unifiedPlaylist;
|
|
|
this.curIndex = unifiedIndex;
|
|
this.curIndex = unifiedIndex;
|
|
|
this.currentSong = unifiedSong || undefined;
|
|
this.currentSong = unifiedSong || undefined;
|
|
|
|
|
+
|
|
|
|
|
+ // 关键修复:如果有当前歌曲,立即更新UI显示信息
|
|
|
|
|
+ if (this.currentSong) {
|
|
|
|
|
+ this.videoUrl = this.currentSong.filePath;
|
|
|
|
|
+ this.name = this.currentSong.name;
|
|
|
|
|
+ this.artist = this.currentSong.artist;
|
|
|
|
|
+ this.cover = this.currentSong.pixelMapPath;
|
|
|
|
|
+
|
|
|
|
|
+ LogUtils.getInstance().LOGI(`LocalMusic: Updated UI with current song: ${this.currentSong.name}, path: ${this.currentSong.filePath}`);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
LogUtils.getInstance().LOGI(`Heanup LocalMusic: Using playlist from UnifiedPlayerService - ${this.songList.length} songs, index ${this.curIndex}, current song: ${this.currentSong?.name || 'null'}`);
|
|
LogUtils.getInstance().LOGI(`Heanup LocalMusic: Using playlist from UnifiedPlayerService - ${this.songList.length} songs, index ${this.curIndex}, current song: ${this.currentSong?.name || 'null'}`);
|
|
|
} else {
|
|
} else {
|
|
|
// 回退到旧的存储方式
|
|
// 回退到旧的存储方式
|
|
@@ -966,6 +992,7 @@ export struct LocalMusic {
|
|
|
/**
|
|
/**
|
|
|
* 页面显示时同步播放状态,修复音频中断后的状态不一致问题
|
|
* 页面显示时同步播放状态,修复音频中断后的状态不一致问题
|
|
|
* 优化:使用异步执行,避免阻塞页面显示
|
|
* 优化:使用异步执行,避免阻塞页面显示
|
|
|
|
|
+ * 修复:确保进度定时器在播放状态下正确启动
|
|
|
*/
|
|
*/
|
|
|
private syncPlaybackStateOnShow(): void {
|
|
private syncPlaybackStateOnShow(): void {
|
|
|
// 异步执行状态同步,避免阻塞页面显示
|
|
// 异步执行状态同步,避免阻塞页面显示
|
|
@@ -984,6 +1011,31 @@ export struct LocalMusic {
|
|
|
this.playChange();
|
|
this.playChange();
|
|
|
this.watchStatus(); // 现在已优化为异步执行
|
|
this.watchStatus(); // 现在已优化为异步执行
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 关键修复:确保当前歌曲信息与播放器状态同步
|
|
|
|
|
+ const currentSong = this.unifiedPlayerService.getCurrentSong();
|
|
|
|
|
+ if (currentSong && currentSong !== this.currentSong) {
|
|
|
|
|
+ LogUtils.getInstance().LOGI(`onPageShow: Syncing current song info from service: ${currentSong.name}`);
|
|
|
|
|
+ this.currentSong = currentSong;
|
|
|
|
|
+ this.videoUrl = currentSong.filePath;
|
|
|
|
|
+ this.name = currentSong.name;
|
|
|
|
|
+ this.artist = currentSong.artist;
|
|
|
|
|
+ this.cover = currentSong.pixelMapPath;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 关键修复:确保在播放状态下启动进度定时器
|
|
|
|
|
+ if (actualPlaying) {
|
|
|
|
|
+ LogUtils.getInstance().LOGI(`onPageShow: Player is playing, ensuring progress timer is running`);
|
|
|
|
|
+ this.mDestroyPage = false; // 确保进度更新不被阻止
|
|
|
|
|
+ this.stopProgressTask(); // 先停止现有定时器
|
|
|
|
|
+ this.startProgressTask(); // 重新启动定时器
|
|
|
|
|
+
|
|
|
|
|
+ // 立即更新一次进度,确保UI显示最新状态
|
|
|
|
|
+ this.setProgress();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ LogUtils.getInstance().LOGI(`onPageShow: Player not playing, stopping progress timer`);
|
|
|
|
|
+ this.stopProgressTask();
|
|
|
|
|
+ }
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
LogUtils.getInstance().LOGI(`syncPlaybackStateOnShow error: ${error}`);
|
|
LogUtils.getInstance().LOGI(`syncPlaybackStateOnShow error: ${error}`);
|
|
|
}
|
|
}
|
|
@@ -11268,51 +11320,66 @@ export struct LocalMusic {
|
|
|
|
|
|
|
|
|
|
|
|
|
private setProgress() {
|
|
private setProgress() {
|
|
|
- let ijkPlayer=this.unifiedPlayerService.getIjkPlayer() as IjkMediaPlayer;
|
|
|
|
|
- let position = ijkPlayer.getCurrentPosition();
|
|
|
|
|
- let duration = ijkPlayer.getDuration();
|
|
|
|
|
- let pos = 0;
|
|
|
|
|
- if (duration > 0) {
|
|
|
|
|
- this.slideEnable = true;
|
|
|
|
|
- let curPercent = position / duration;
|
|
|
|
|
- pos = curPercent * 100;
|
|
|
|
|
- if (pos > this.PROGRESS_MAX_VALUE) {
|
|
|
|
|
- this.progressValue = this.PROGRESS_MAX_VALUE
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ let ijkPlayer = this.unifiedPlayerService.getIjkPlayer() as IjkMediaPlayer;
|
|
|
|
|
+
|
|
|
|
|
+ // 关键修复:检查播放器是否存在
|
|
|
|
|
+ if (!ijkPlayer) {
|
|
|
|
|
+ LogUtils.getInstance().LOGI("setProgress: IJK player not available");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let position = ijkPlayer.getCurrentPosition();
|
|
|
|
|
+ let duration = ijkPlayer.getDuration();
|
|
|
|
|
+ let pos = 0;
|
|
|
|
|
+
|
|
|
|
|
+ // 关键修复:添加详细的调试日志
|
|
|
|
|
+ LogUtils.getInstance().LOGI(`setProgress: position=${position}ms, duration=${duration}ms`);
|
|
|
|
|
+
|
|
|
|
|
+ if (duration > 0) {
|
|
|
|
|
+ this.slideEnable = true;
|
|
|
|
|
+ let curPercent = position / duration;
|
|
|
|
|
+ pos = curPercent * 100;
|
|
|
|
|
+ if (pos > this.PROGRESS_MAX_VALUE) {
|
|
|
|
|
+ this.progressValue = this.PROGRESS_MAX_VALUE
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.progressValue = pos;
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
- this.progressValue = pos;
|
|
|
|
|
|
|
+ // 关键修复:duration为0时的处理
|
|
|
|
|
+ LogUtils.getInstance().LOGI("setProgress: Duration is 0, disabling slider");
|
|
|
|
|
+ this.slideEnable = false;
|
|
|
|
|
+ this.progressValue = 0;
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
- // LogUtils.getInstance()
|
|
|
|
|
- // .LOGI("setProgress position:" + position + ",duration:" + duration + ",progressValue:" + pos);
|
|
|
|
|
- this.totalTime = this.stringForTime(duration);
|
|
|
|
|
- if (position > duration) {
|
|
|
|
|
- position = duration;
|
|
|
|
|
- }
|
|
|
|
|
- this.isCurrentTime = true;
|
|
|
|
|
- this.lyricController.updatePosition(position + this.timeOffset * 1000)
|
|
|
|
|
- this.lyricControllerXF.updatePosition(position + this.timeOffset * 1000)
|
|
|
|
|
- this.lyricControllerSingle.updatePosition(position + this.timeOffset * 1000)
|
|
|
|
|
-
|
|
|
|
|
- this.currentTime = this.stringForTime(position);
|
|
|
|
|
- this.isCurrentTime = false
|
|
|
|
|
|
|
+ this.totalTime = this.stringForTime(duration);
|
|
|
|
|
+ if (position > duration) {
|
|
|
|
|
+ position = duration;
|
|
|
|
|
+ }
|
|
|
|
|
+ this.isCurrentTime = true;
|
|
|
|
|
+ this.lyricController.updatePosition(position + this.timeOffset * 1000)
|
|
|
|
|
+ this.lyricControllerXF.updatePosition(position + this.timeOffset * 1000)
|
|
|
|
|
+ this.lyricControllerSingle.updatePosition(position + this.timeOffset * 1000)
|
|
|
|
|
|
|
|
|
|
+ this.currentTime = this.stringForTime(position);
|
|
|
|
|
+ this.isCurrentTime = false
|
|
|
|
|
|
|
|
- if (ijkPlayer.isPlaying()) {
|
|
|
|
|
- this.randomColor =
|
|
|
|
|
- `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`
|
|
|
|
|
|
|
+ if (ijkPlayer.isPlaying()) {
|
|
|
|
|
+ this.randomColor =
|
|
|
|
|
+ `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`
|
|
|
|
|
|
|
|
- // 判断是否播放到结束时间
|
|
|
|
|
- if (this.isOpenJump && duration > this.jumpEndTime * 1000) {
|
|
|
|
|
- if (position >= duration - this.jumpEndTime * 1000) {
|
|
|
|
|
- this.playNext()
|
|
|
|
|
|
|
+ // 判断是否播放到结束时间
|
|
|
|
|
+ if (this.isOpenJump && duration > this.jumpEndTime * 1000) {
|
|
|
|
|
+ if (position >= duration - this.jumpEndTime * 1000) {
|
|
|
|
|
+ this.playNext()
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- this.randomColor = 'rbg(0,0,0)'
|
|
|
|
|
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.randomColor = 'rbg(0,0,0)'
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ LogUtils.getInstance().LOGI(`setProgress error: ${error}`);
|
|
|
}
|
|
}
|
|
|
// try {
|
|
// try {
|
|
|
// // 优先从UnifiedPlayerService获取进度信息
|
|
// // 优先从UnifiedPlayerService获取进度信息
|