|
|
@@ -48,7 +48,8 @@ import {
|
|
|
PLAYER_PROGRESS_CHANGED_EVENT
|
|
|
} from '../common/widget/WidgetEventConstants';
|
|
|
import {
|
|
|
-// DeviceChangeReason,
|
|
|
+ IjkMediaPlayer,
|
|
|
+ // DeviceChangeReason,
|
|
|
InterruptEvent,
|
|
|
InterruptHintType,
|
|
|
LogUtils
|
|
|
@@ -550,6 +551,8 @@ export struct LocalMusic {
|
|
|
this.localMusic.oldSeconds = 0;
|
|
|
this.localMusic.currentTime = "00:00";
|
|
|
this.localMusic.lastSongPath = song.filePath; // 更新当前歌曲路径
|
|
|
+ this.localMusic.justSwitched = true; // 标记歌曲刚刚切换
|
|
|
+
|
|
|
|
|
|
console.log(`Heanup onSongChanged - 重置后 oldSeconds: ${this.localMusic.oldSeconds}, currentTime: ${this.localMusic.currentTime}`);
|
|
|
|
|
|
@@ -4812,6 +4815,14 @@ export struct LocalMusic {
|
|
|
this.cover = this.currentSong.pixelMapPath
|
|
|
this.artist = this.currentSong.artist
|
|
|
|
|
|
+ // 重置时间显示状态,防止新歌曲时间显示被上一首歌曲的时间"卡住"
|
|
|
+ this.oldSeconds = 0;
|
|
|
+ this.currentTime = "00:00";
|
|
|
+ this.lastSongPath = this.currentSong.filePath;
|
|
|
+ this.justSwitched = true; // 标记歌曲刚刚切换
|
|
|
+
|
|
|
+ console.log(`Heanup doPlay - 重置时间显示状态: oldSeconds=${this.oldSeconds}, currentTime=${this.currentTime}`);
|
|
|
+
|
|
|
// 同步播放列表到UnifiedPlayerService
|
|
|
this.syncPlaylistToService();
|
|
|
|
|
|
@@ -6586,6 +6597,8 @@ export struct LocalMusic {
|
|
|
@State isSeekTo: boolean = false;
|
|
|
@State isCurrentTime: boolean = false;
|
|
|
@State lastSongPath: string = ""; // 用于检测歌曲切换
|
|
|
+ @State justSwitched: boolean = false; // 标记歌曲刚刚切换
|
|
|
+ @State lastSwitchTime: number = 0; // 记录最后一次歌曲切换的时间戳
|
|
|
@State videoWidth: string = '100%';
|
|
|
@State videoHeight: string = '100%';
|
|
|
@State initAspectRatio: number = 1;
|
|
|
@@ -9919,37 +9932,64 @@ export struct LocalMusic {
|
|
|
try {
|
|
|
// 检测歌曲是否发生切换(额外保障机制)
|
|
|
const currentSongPath = this.currentSong?.filePath || "";
|
|
|
+ let isSongChanged = false;
|
|
|
if (this.lastSongPath !== currentSongPath && currentSongPath !== "") {
|
|
|
console.log(`Heanup 在进度更新中检测到歌曲切换: ${this.lastSongPath} -> ${currentSongPath}`);
|
|
|
- console.log(`Heanup 歌曲切换前 oldSeconds: ${this.oldSeconds}`);
|
|
|
+ console.log(`Heanup 歌曲切换前 oldSeconds: ${this.oldSeconds}, currentTime: ${this.currentTime}`);
|
|
|
+ // 立即重置时间显示状态,防止新歌曲时间显示被上一首歌曲的时间"卡住"
|
|
|
this.oldSeconds = 0;
|
|
|
+ this.currentTime = "00:00";
|
|
|
this.lastSongPath = currentSongPath;
|
|
|
- console.log(`Heanup 歌曲切换后 oldSeconds: ${this.oldSeconds}`);
|
|
|
+ this.justSwitched = true; // 标记歌曲刚刚切换
|
|
|
+ isSongChanged = true;
|
|
|
+ console.log(`Heanup 歌曲切换后 oldSeconds: ${this.oldSeconds}, currentTime: ${this.currentTime}`);
|
|
|
+ // 歌曲切换时,强制将播放位置重置为0,忽略服务报告的位置
|
|
|
+ progress.currentPosition = 0;
|
|
|
+ console.log(`Heanup 歌曲切换,强制progress.currentPosition为0`);
|
|
|
+
|
|
|
+ // 立即返回,不更新进度,等待新歌曲开始播放
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- // 更新进度条
|
|
|
- if (progress.duration > 0) {
|
|
|
- this.slideEnable = true;
|
|
|
- let curPercent = progress.currentPosition / progress.duration;
|
|
|
- let pos = curPercent * 100;
|
|
|
- if (pos > this.PROGRESS_MAX_VALUE) {
|
|
|
- this.progressValue = this.PROGRESS_MAX_VALUE;
|
|
|
- } else {
|
|
|
- this.progressValue = pos;
|
|
|
+ // 直接使用ijkplayer获取播放进度,避免状态同步延迟
|
|
|
+ try {
|
|
|
+ const ijkPlayer = this.unifiedPlayerService.getIjkPlayer();
|
|
|
+ if (ijkPlayer && ijkPlayer.isPlaying()) {
|
|
|
+ const currentPosition = ijkPlayer.getCurrentPosition();
|
|
|
+ const duration = ijkPlayer.getDuration();
|
|
|
+
|
|
|
+ if (duration > 0 && currentPosition >= 0) {
|
|
|
+ // 更新进度条
|
|
|
+ this.slideEnable = true;
|
|
|
+ let curPercent = currentPosition / duration;
|
|
|
+ let pos = curPercent * 100;
|
|
|
+ if (pos > this.PROGRESS_MAX_VALUE) {
|
|
|
+ this.progressValue = this.PROGRESS_MAX_VALUE;
|
|
|
+ } else {
|
|
|
+ this.progressValue = pos;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新时间显示
|
|
|
+ this.totalTime = this.stringForTime(duration);
|
|
|
+ console.log(`Heanup 当前时间 (直接从ijkplayer获取) - ${currentPosition} / ${duration}`)
|
|
|
+ console.log(`Heanup 更新前 - oldSeconds: ${this.oldSeconds}, currentTime: ${this.currentTime}`)
|
|
|
+ this.isCurrentTime = true;
|
|
|
+ this.currentTime = this.stringForTime(currentPosition);
|
|
|
+ this.isCurrentTime = false;
|
|
|
+ console.log(`Heanup 更新后 - oldSeconds: ${this.oldSeconds}, currentTime: ${this.currentTime}`)
|
|
|
+
|
|
|
+ // 继续执行后续的歌词更新等逻辑
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (error) {
|
|
|
+ console.error('LocalMusic: 获取ijkplayer播放进度失败', error);
|
|
|
+ // 如果直接获取失败,回退到使用服务状态
|
|
|
+ this.updateProgressFromServiceState(progress);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- // 更新时间显示
|
|
|
- this.totalTime = this.stringForTime(progress.duration);
|
|
|
- if (progress.currentPosition > progress.duration) {
|
|
|
- progress.currentPosition = progress.duration;
|
|
|
- }
|
|
|
- console.log(`Heanup 当前时间 - ${progress.currentPosition} / ${progress.duration}`)
|
|
|
- console.log(`Heanup 更新前 - oldSeconds: ${this.oldSeconds}, currentTime: ${this.currentTime}`)
|
|
|
- this.isCurrentTime = true;
|
|
|
- this.currentTime = this.stringForTime(progress.currentPosition);
|
|
|
- this.isCurrentTime = false;
|
|
|
- console.log(`Heanup 更新后 - oldSeconds: ${this.oldSeconds}, currentTime: ${this.currentTime}`)
|
|
|
+ // 如果直接获取ijkplayer失败或者不在播放状态,使用服务状态
|
|
|
+ this.updateProgressFromServiceState(progress);
|
|
|
|
|
|
// 更新歌词位置
|
|
|
const lyricPosition = progress.currentPosition + this.timeOffset * 1000;
|
|
|
@@ -9985,6 +10025,35 @@ export struct LocalMusic {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 从服务状态更新播放进度(回退方案)
|
|
|
+ */
|
|
|
+ private updateProgressFromServiceState(progress: PlayProgress) {
|
|
|
+ // 更新进度条
|
|
|
+ if (progress.duration > 0) {
|
|
|
+ this.slideEnable = true;
|
|
|
+ let curPercent = progress.currentPosition / progress.duration;
|
|
|
+ let pos = curPercent * 100;
|
|
|
+ if (pos > this.PROGRESS_MAX_VALUE) {
|
|
|
+ this.progressValue = this.PROGRESS_MAX_VALUE;
|
|
|
+ } else {
|
|
|
+ this.progressValue = pos;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新时间显示
|
|
|
+ this.totalTime = this.stringForTime(progress.duration);
|
|
|
+ if (progress.currentPosition > progress.duration) {
|
|
|
+ progress.currentPosition = progress.duration;
|
|
|
+ }
|
|
|
+ console.log(`Heanup 当前时间 (从服务状态获取) - ${progress.currentPosition} / ${progress.duration}`)
|
|
|
+ console.log(`Heanup 更新前 - oldSeconds: ${this.oldSeconds}, currentTime: ${this.currentTime}`)
|
|
|
+ this.isCurrentTime = true;
|
|
|
+ this.currentTime = this.stringForTime(progress.currentPosition);
|
|
|
+ this.isCurrentTime = false;
|
|
|
+ console.log(`Heanup 更新后 - oldSeconds: ${this.oldSeconds}, currentTime: ${this.currentTime}`)
|
|
|
+ }
|
|
|
+
|
|
|
updateLastPlayTimeStr(filePath: string) {
|
|
|
let lastPlayTime = DateUtil.getTodayStr('yyyy-MM-dd HH:mm:ss')
|
|
|
this.table.updateLastPlayedStrByFilePath(filePath, lastPlayTime, (success: boolean, error?: string) => {
|
|
|
@@ -10005,85 +10074,182 @@ export struct LocalMusic {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 纯粹的时间格式化函数,不包含任何业务逻辑
|
|
|
private stringForTime(timeMs: number): string {
|
|
|
- let totalSeconds: number | string = (timeMs / 1000);
|
|
|
- let newSeconds: number | string = totalSeconds % 60;
|
|
|
- let minutes: number | string = (totalSeconds / 60) % 60;
|
|
|
- let hours: number | string = totalSeconds / 3600;
|
|
|
- //LogUtils.getInstance().LOGI("stringForTime hours:" + hours + ",minutes:" + minutes + ",seconds:" + newSeconds);
|
|
|
- hours = this.completionNum(Math.floor(Math.floor(hours * 100) / 100));
|
|
|
- minutes = this.completionNum(Math.floor(Math.floor(minutes * 100) / 100));
|
|
|
- newSeconds = Math.floor(Math.floor(newSeconds * 100) / 100)
|
|
|
+ let totalSeconds: number = Math.floor(timeMs / 1000);
|
|
|
+ let seconds: number = totalSeconds % 60;
|
|
|
+ let minutes: number = Math.floor(totalSeconds / 60) % 60;
|
|
|
+ let hours: number = Math.floor(totalSeconds / 3600);
|
|
|
+
|
|
|
+ // 防抖逻辑:只在当前播放时间更新时生效
|
|
|
if (this.isCurrentTime) {
|
|
|
- if (this.oldSeconds < newSeconds || newSeconds === 0 || this.isSeekTo) {
|
|
|
- this.oldSeconds = newSeconds
|
|
|
+ // 如果歌曲刚刚切换,强制重置并使用新时间
|
|
|
+ if (this.justSwitched) {
|
|
|
+ console.log(`Heanup stringForTime歌曲刚切换 - 强制重置oldSeconds: ${this.oldSeconds} -> ${seconds}, 强制使用新时间`);
|
|
|
+ this.oldSeconds = seconds; // 直接使用新时间
|
|
|
+ this.justSwitched = false; // 重置标志
|
|
|
+ this.lastSwitchTime = Date.now(); // 记录切换时间
|
|
|
+ } else if (this.isSeekTo) {
|
|
|
+ // 如果是拖动进度条,直接使用新时间
|
|
|
+ console.log(`Heanup stringForTime拖动进度条 - 直接使用新时间: ${seconds}`);
|
|
|
+ this.oldSeconds = seconds;
|
|
|
} else {
|
|
|
- newSeconds = this.oldSeconds
|
|
|
+ // 正常播放时的防抖逻辑
|
|
|
+ // 检查是否在切换后的冷却期内(切换后5秒内允许更大的时间跳跃)
|
|
|
+ const timeSinceSwitch = this.lastSwitchTime ? Date.now() - this.lastSwitchTime : Number.MAX_VALUE;
|
|
|
+ const isInCooldown = timeSinceSwitch < 5000; // 5秒冷却期
|
|
|
+
|
|
|
+ // 如果时间差值过大,根据情况处理
|
|
|
+ const timeDiff = Math.abs(seconds - this.oldSeconds);
|
|
|
+
|
|
|
+ if (timeDiff > 10) {
|
|
|
+ // 如果在冷却期内,允许更大的时间跳跃(可能是新歌曲开始播放)
|
|
|
+ if (isInCooldown) {
|
|
|
+ console.log(`Heanup stringForTime切换后冷却期内检测到时间跳跃 - oldSeconds: ${this.oldSeconds}, newSeconds: ${seconds}, diff: ${timeDiff}, 允许跳跃`);
|
|
|
+ this.oldSeconds = seconds;
|
|
|
+ } else {
|
|
|
+ // 不在冷却期内,可能是异常情况,记录但使用新时间
|
|
|
+ console.log(`Heanup stringForTime检测到异常时间跳跃 - oldSeconds: ${this.oldSeconds}, newSeconds: ${seconds}, diff: ${timeDiff},直接使用新时间`);
|
|
|
+ this.oldSeconds = seconds;
|
|
|
+ }
|
|
|
+ } else if (this.oldSeconds <= seconds || seconds === 0) {
|
|
|
+ // 正常时间递进或重置为0
|
|
|
+ console.log(`Heanup stringForTime正常更新 - oldSeconds: ${this.oldSeconds} -> ${seconds}`);
|
|
|
+ this.oldSeconds = seconds;
|
|
|
+ } else {
|
|
|
+ // 时间倒退,使用防抖
|
|
|
+ console.log(`Heanup stringForTime防抖 - oldSeconds: ${this.oldSeconds}, newSeconds: ${seconds}, 使用oldSeconds`);
|
|
|
+ seconds = this.oldSeconds;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- newSeconds = this.completionNum(newSeconds);
|
|
|
+
|
|
|
+ const hoursStr = this.completionNum(hours);
|
|
|
+ const minutesStr = this.completionNum(minutes);
|
|
|
+ const secondsStr = this.completionNum(seconds);
|
|
|
+
|
|
|
if (hours > 0) {
|
|
|
- return hours + ":" + minutes + ":" + newSeconds;
|
|
|
+ return `${hoursStr}:${minutesStr}:${secondsStr}`;
|
|
|
} else {
|
|
|
- return minutes + ":" + newSeconds;
|
|
|
+ return `${minutesStr}:${secondsStr}`;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private setProgress() {
|
|
|
- try {
|
|
|
- // 优先从UnifiedPlayerService获取进度信息
|
|
|
- const currentState = this.unifiedPlayerService.getCurrentState();
|
|
|
- let position = currentState.currentPosition;
|
|
|
- let duration = currentState.duration;
|
|
|
-
|
|
|
- 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
|
|
|
- } else {
|
|
|
- this.progressValue = pos;
|
|
|
- }
|
|
|
+ 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
|
|
|
+ } else {
|
|
|
+ this.progressValue = pos;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- this.totalTime = this.stringForTime(duration);
|
|
|
- if (position > duration) {
|
|
|
- position = duration;
|
|
|
- }
|
|
|
- this.isCurrentTime = true;
|
|
|
-
|
|
|
- // 更新歌词位置
|
|
|
- const lyricPosition = position + this.timeOffset * 1000;
|
|
|
- this.lyricController.updatePosition(lyricPosition);
|
|
|
- this.lyricControllerXF.updatePosition(lyricPosition);
|
|
|
- this.lyricControllerSingle.updatePosition(lyricPosition);
|
|
|
|
|
|
- this.currentTime = this.stringForTime(position);
|
|
|
- this.isCurrentTime = false
|
|
|
+ // 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)
|
|
|
|
|
|
- // 检查播放状态以更新随机颜色和跳过逻辑
|
|
|
- const isPlaying = currentState.isPlaying;
|
|
|
- if (isPlaying) {
|
|
|
- this.randomColor =
|
|
|
- `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`
|
|
|
+ this.currentTime = this.stringForTime(position);
|
|
|
+ this.isCurrentTime = false
|
|
|
|
|
|
- // 判断是否播放到结束时间
|
|
|
- if (this.isOpenJump && duration > this.jumpEndTime * 1000) {
|
|
|
- if (position >= duration - this.jumpEndTime * 1000) {
|
|
|
- this.playNext()
|
|
|
- }
|
|
|
+
|
|
|
+ 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()
|
|
|
+ this.broadcastProgressIfNeeded();
|
|
|
}
|
|
|
- } else {
|
|
|
- this.randomColor = 'rbg(0,0,0)'
|
|
|
}
|
|
|
|
|
|
- // 节流广播进度更新到卡片
|
|
|
- this.broadcastProgressIfNeeded();
|
|
|
- } catch (error) {
|
|
|
- LogUtils.getInstance().LOGI(`LocalMusic setProgress error: ${error}`);
|
|
|
+ } else {
|
|
|
+ this.randomColor = 'rbg(0,0,0)'
|
|
|
+
|
|
|
}
|
|
|
+ // try {
|
|
|
+ // // 优先从UnifiedPlayerService获取进度信息
|
|
|
+ // const currentState = this.unifiedPlayerService.getCurrentState();
|
|
|
+ // let position = currentState.currentPosition;
|
|
|
+ // let duration = currentState.duration;
|
|
|
+ //
|
|
|
+ // // 检测歌曲切换并重置播放位置
|
|
|
+ // const currentSongPath = this.currentSong?.filePath || "";
|
|
|
+ // if (this.lastSongPath !== currentSongPath && currentSongPath !== "") {
|
|
|
+ // console.log(`Heanup setProgress检测到歌曲切换,重置position: ${position} -> 0`);
|
|
|
+ // this.oldSeconds = 0;
|
|
|
+ // this.currentTime = "00:00";
|
|
|
+ // this.lastSongPath = currentSongPath;
|
|
|
+ // position = 0; // 强制重置播放位置
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // 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
|
|
|
+ // } else {
|
|
|
+ // this.progressValue = pos;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // this.totalTime = this.stringForTime(duration);
|
|
|
+ // if (position > duration) {
|
|
|
+ // position = duration;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // // 更新歌词位置
|
|
|
+ // const lyricPosition = position + this.timeOffset * 1000;
|
|
|
+ // this.lyricController.updatePosition(lyricPosition);
|
|
|
+ // this.lyricControllerXF.updatePosition(lyricPosition);
|
|
|
+ // this.lyricControllerSingle.updatePosition(lyricPosition);
|
|
|
+ //
|
|
|
+ // this.isCurrentTime = true;
|
|
|
+ // this.currentTime = this.stringForTime(position);
|
|
|
+ // this.isCurrentTime = false;
|
|
|
+ //
|
|
|
+ // // 检查播放状态以更新随机颜色和跳过逻辑
|
|
|
+ // const isPlaying = currentState.isPlaying;
|
|
|
+ // if (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()
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // this.randomColor = 'rbg(0,0,0)'
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // 节流广播进度更新到卡片
|
|
|
+ // this.broadcastProgressIfNeeded();
|
|
|
+ // } catch (error) {
|
|
|
+ // LogUtils.getInstance().LOGI(`LocalMusic setProgress error: ${error}`);
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
private startProgressTask() {
|
|
|
@@ -10106,16 +10272,6 @@ export struct LocalMusic {
|
|
|
this.replayVisible = Visibility.None;
|
|
|
}
|
|
|
|
|
|
- private hideLoadIng() {
|
|
|
- this.loadingVisible = Visibility.None;
|
|
|
- this.replayVisible = Visibility.None;
|
|
|
- }
|
|
|
-
|
|
|
- private showRePlay() {
|
|
|
- this.loadingVisible = Visibility.None;
|
|
|
- this.replayVisible = Visibility.Visible;
|
|
|
- }
|
|
|
-
|
|
|
// 原来的 play 方法已移除,播放逻辑现在由 UnifiedPlayerService 统一处理
|
|
|
// private async play(url: string) { ... } 已移除
|
|
|
|
|
|
@@ -10148,25 +10304,6 @@ export struct LocalMusic {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public async setAvSessionListener() {
|
|
|
- if (!this.avSessionController) {
|
|
|
- return;
|
|
|
- }
|
|
|
- this.avSessionController.getAvSession()?.on('play', this.sessionPlayCallback);
|
|
|
- this.avSessionController.getAvSession()?.on('pause', this.sessionPauseCallback);
|
|
|
- this.avSessionController.getAvSession()?.on('stop', this.sessionStopCallback);
|
|
|
- this.avSessionController.getAvSession()?.on('playNext', this.sessionPlayNextCallback);
|
|
|
- this.avSessionController.getAvSession()?.on('playPrevious', this.sessionPlayPreviousCallback);
|
|
|
- this.avSessionController.getAvSession()?.on('fastForward', this.sessionFastForwardCallback);
|
|
|
- this.avSessionController.getAvSession()?.on('rewind', this.sessionRewindCallback);
|
|
|
- this.avSessionController.getAvSession()?.on('seek', this.sessionSeekCallback);
|
|
|
- this.avSessionController.getAvSession()?.on('setLoopMode', this.sessionSetLoopModeCallback);
|
|
|
- this.avSessionController.getAvSession()?.on('toggleFavorite', this.sessionToggleFavoriteCallback);
|
|
|
-
|
|
|
- this.avSessionController.getAvSession()?.on('outputDeviceChange', this.sessionOutputDeviceChange)
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
setLoopMode() {
|
|
|
let itype = this.playType + 1
|
|
|
if (itype >= 4) {
|
|
|
@@ -10538,14 +10675,14 @@ export struct LocalMusic {
|
|
|
const currentState = this.unifiedPlayerService.getCurrentState();
|
|
|
const curPosition = currentState.currentPosition;
|
|
|
let seeTime = curPosition + time * 1000;
|
|
|
-
|
|
|
+
|
|
|
// 限制 seekValue 在合法范围内
|
|
|
if (seeTime < 0) {
|
|
|
seeTime = 0;
|
|
|
} else if (seeTime > currentState.duration) {
|
|
|
seeTime = currentState.duration;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Logger.info('onecold seeTime= ' + seeTime)
|
|
|
this.setSeekToActionProgress(seeTime)
|
|
|
this.seekTo(seeTime + "")
|
|
|
@@ -10581,7 +10718,7 @@ export struct LocalMusic {
|
|
|
}
|
|
|
this.isCurrentTime = true;
|
|
|
this.currentTime = this.stringForTime(position);
|
|
|
- this.isCurrentTime = false
|
|
|
+ this.isCurrentTime = false;
|
|
|
}
|
|
|
|
|
|
private sessionRewindCallback = (time?: number) => {
|
|
|
@@ -10616,35 +10753,50 @@ export struct LocalMusic {
|
|
|
}
|
|
|
|
|
|
private async pause() {
|
|
|
- try {
|
|
|
- // 使用UnifiedPlayerService暂停播放
|
|
|
- await this.unifiedPlayerService.pause();
|
|
|
-
|
|
|
- // 保持原有的UI更新逻辑
|
|
|
+
|
|
|
+ if (this.unifiedPlayerService.getIjkPlayer()?.isPlaying()){
|
|
|
+ this.savePlaybackPosition();
|
|
|
+ this.unifiedPlayerService.pause();
|
|
|
this.setProgress();
|
|
|
this.mDestroyPage = true;
|
|
|
this.CONTROL_PlayStatus = PlayStatus.PAUSE;
|
|
|
- this.setIsPlaying(false);
|
|
|
- this.updateSessionPlayState(false);
|
|
|
+ this.updateSessionPlayState(false)
|
|
|
this.playChange()
|
|
|
-
|
|
|
if (this.pipController) {
|
|
|
this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
|
|
|
PiPWindow.PiPControlStatus.PAUSE);
|
|
|
}
|
|
|
-
|
|
|
- LogUtils.getInstance().LOGI("LocalMusic: pause completed via UnifiedPlayerService");
|
|
|
- } catch (error) {
|
|
|
- LogUtils.getInstance().LOGI(`LocalMusic pause error: ${error}`);
|
|
|
- ToastUtil.showToast(`暂停失败: ${error}`);
|
|
|
}
|
|
|
+
|
|
|
+ // try {
|
|
|
+ // // 使用UnifiedPlayerService暂停播放
|
|
|
+ // await this.unifiedPlayerService.pause();
|
|
|
+ //
|
|
|
+ // // 保持原有的UI更新逻辑
|
|
|
+ // this.setProgress();
|
|
|
+ // this.mDestroyPage = true;
|
|
|
+ // this.CONTROL_PlayStatus = PlayStatus.PAUSE;
|
|
|
+ // this.setIsPlaying(false);
|
|
|
+ // this.updateSessionPlayState(false);
|
|
|
+ // this.playChange()
|
|
|
+ //
|
|
|
+ // if (this.pipController) {
|
|
|
+ // this.pipController.updatePiPControlStatus(PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE,
|
|
|
+ // PiPWindow.PiPControlStatus.PAUSE);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // LogUtils.getInstance().LOGI("LocalMusic: pause completed via UnifiedPlayerService");
|
|
|
+ // } catch (error) {
|
|
|
+ // LogUtils.getInstance().LOGI(`LocalMusic pause error: ${error}`);
|
|
|
+ // ToastUtil.showToast(`暂停失败: ${error}`);
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
private async stop() {
|
|
|
try {
|
|
|
// 使用UnifiedPlayerService停止播放
|
|
|
await this.unifiedPlayerService.stop();
|
|
|
-
|
|
|
+
|
|
|
// 保持原有的UI更新逻辑
|
|
|
this.stopProgressTask();
|
|
|
this.CONTROL_PlayStatus = PlayStatus.INIT;
|
|
|
@@ -10652,7 +10804,7 @@ export struct LocalMusic {
|
|
|
this.updateSessionPlayState(false)
|
|
|
this.playChange()
|
|
|
this.watchStatus();
|
|
|
-
|
|
|
+
|
|
|
LogUtils.getInstance().LOGI("LocalMusic: stop completed via UnifiedPlayerService");
|
|
|
} catch (error) {
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic stop error: ${error}`);
|
|
|
@@ -10671,7 +10823,7 @@ export struct LocalMusic {
|
|
|
|
|
|
// 如果播放位置接近视频末尾,则保存 position 为 0
|
|
|
const playbackPosition = (duration - position < threshold) ? 0 : position;
|
|
|
-
|
|
|
+
|
|
|
// 同时保存到PreferencesUtil和AppStorage,确保卡片也能访问
|
|
|
PreferencesUtil.putSync(this.videoUrl, playbackPosition);
|
|
|
AppStorage.setOrCreate(`playback_${this.videoUrl}`, playbackPosition);
|
|
|
@@ -10689,7 +10841,7 @@ export struct LocalMusic {
|
|
|
if (position === 0) {
|
|
|
position = PreferencesUtil.getNumberSync(this.videoUrl, 0);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// ToastUtil.showToast('position = ' + position)
|
|
|
if (position > 0) {
|
|
|
// ToastUtil.showToast('seekTo = ' + position)
|
|
|
@@ -10702,14 +10854,14 @@ export struct LocalMusic {
|
|
|
try {
|
|
|
// 使用UnifiedPlayerService进行拖动
|
|
|
await this.unifiedPlayerService.seekTo(value);
|
|
|
-
|
|
|
+
|
|
|
// 保持原有的UI更新逻辑
|
|
|
this.setProgress()
|
|
|
-
|
|
|
+
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic: seekTo ${value} completed via UnifiedPlayerService`);
|
|
|
} catch (error) {
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic seekTo error: ${error}`);
|
|
|
-
|
|
|
+
|
|
|
// 如果是WMA格式错误,显示特定提示
|
|
|
if (error.toString().includes('WMA format')) {
|
|
|
ToastUtil.showToast('wma格式不支持拖动快进。');
|
|
|
@@ -10731,7 +10883,7 @@ export struct LocalMusic {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
// 如果未开始播放或队列为空
|
|
|
if (this.curIndex === -1 || this.songList.length === 0) {
|
|
|
@@ -10743,24 +10895,24 @@ export struct LocalMusic {
|
|
|
|
|
|
// 插入到当前索引+1的位置
|
|
|
const insertPos = this.curIndex + 1;
|
|
|
-
|
|
|
+
|
|
|
// 使用UnifiedPlayerService添加到播放列表
|
|
|
this.unifiedPlayerService.addToPlaylist(song, insertPos);
|
|
|
-
|
|
|
+
|
|
|
// 更新本地播放列表
|
|
|
this.songList.splice(insertPos, 0, song);
|
|
|
this.songList = [...this.songList]; // 触发状态更新
|
|
|
this.sonDataSource.pushArrayData(this.songList);
|
|
|
-
|
|
|
+
|
|
|
// 同步到AppStorage
|
|
|
AppStorage.setOrCreate('songList', this.songList);
|
|
|
-
|
|
|
+
|
|
|
ToastUtil.showToast('已添加至下一首播放')
|
|
|
-
|
|
|
+
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic: Added song to next play via UnifiedPlayerService - ${song.name}`);
|
|
|
} catch (error) {
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic addToNextPlay error: ${error}`);
|
|
|
-
|
|
|
+
|
|
|
// 错误处理:回退到原有逻辑
|
|
|
const insertPos = this.curIndex + 1;
|
|
|
this.songList.splice(insertPos, 0, song);
|
|
|
@@ -10781,7 +10933,7 @@ export struct LocalMusic {
|
|
|
this.randomPlay()
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (ArrayUtil.isNotEmpty(this.songList)) {
|
|
|
// 确保播放列表已同步到UnifiedPlayerService
|
|
|
this.unifiedPlayerService.setPlaylist(this.songList, this.curIndex);
|
|
|
@@ -10801,6 +10953,13 @@ export struct LocalMusic {
|
|
|
this.name = currentSong.name;
|
|
|
this.cover = currentSong.pixelMapPath;
|
|
|
|
|
|
+ // 重置时间显示状态,防止新歌曲时间显示被上一首歌曲的时间"卡住"
|
|
|
+ this.oldSeconds = 0;
|
|
|
+ this.currentTime = "00:00";
|
|
|
+ this.lastSongPath = currentSong.filePath;
|
|
|
+ this.justSwitched = true; // 标记歌曲刚刚切换
|
|
|
+ console.log(`Heanup playNext - 重置时间显示状态: oldSeconds=${this.oldSeconds}, currentTime=${this.currentTime}`);
|
|
|
+
|
|
|
// 同步到AppStorage,确保卡片能获取到最新状态
|
|
|
// AppStorage.setOrCreate('songList', this.songList);
|
|
|
// AppStorage.setOrCreate('currIndex', this.curIndex);
|
|
|
@@ -10984,6 +11143,13 @@ export struct LocalMusic {
|
|
|
this.artist = currentSong.artist;
|
|
|
this.cover = currentSong.pixelMapPath;
|
|
|
|
|
|
+ // 重置时间显示状态,防止新歌曲时间显示被上一首歌曲的时间"卡住"
|
|
|
+ this.oldSeconds = 0;
|
|
|
+ this.currentTime = "00:00";
|
|
|
+ this.lastSongPath = currentSong.filePath;
|
|
|
+ this.justSwitched = true; // 标记歌曲刚刚切换
|
|
|
+ console.log(`Heanup playPrevious - 重置时间显示状态: oldSeconds=${this.oldSeconds}, currentTime=${this.currentTime}`);
|
|
|
+
|
|
|
// 同步到AppStorage,确保卡片能获取到最新状态
|
|
|
AppStorage.setOrCreate('songList', this.songList);
|
|
|
AppStorage.setOrCreate('currIndex', this.curIndex);
|