|
|
@@ -14749,6 +14749,29 @@ export struct LocalMusic {
|
|
|
return duration;
|
|
|
}
|
|
|
|
|
|
+ private getSongDurationMs(song?: VideoItem): number {
|
|
|
+ if (!song || !song.duration) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ const raw = song.duration.trim();
|
|
|
+ if (!raw) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ const parts = raw.split(':').map((part) => Number(part));
|
|
|
+ if (parts.some((part) => Number.isNaN(part))) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ let seconds = 0;
|
|
|
+ if (parts.length === 3) {
|
|
|
+ seconds = parts[0] * 3600 + parts[1] * 60 + parts[2];
|
|
|
+ } else if (parts.length === 2) {
|
|
|
+ seconds = parts[0] * 60 + parts[1];
|
|
|
+ } else if (parts.length === 1) {
|
|
|
+ seconds = parts[0];
|
|
|
+ }
|
|
|
+ return seconds > 0 ? seconds * 1000 : 0;
|
|
|
+ }
|
|
|
+
|
|
|
private updateCastProgress(position: number): void {
|
|
|
const duration = this.getActiveDuration();
|
|
|
if (duration <= 0) {
|
|
|
@@ -15056,19 +15079,20 @@ export struct LocalMusic {
|
|
|
console.info('heanup playNext 1 ', `this.isCastPlaying: ${ this.isCastPlaying}`)
|
|
|
console.info('heanup playNext 2 ', `this.castControllerWrapper: ${this.castControllerWrapper}`)
|
|
|
|
|
|
- // 从 CastController 获取最新的投播状态
|
|
|
- if (this.castControllerWrapper) {
|
|
|
- const controllerIsPlaying = this.castControllerWrapper.getIsCastPlaying();
|
|
|
- console.info('heanup playNext', `从 CastController 获取的 isCastPlaying=${controllerIsPlaying}`);
|
|
|
- this.isCastPlaying = controllerIsPlaying;
|
|
|
- }
|
|
|
-
|
|
|
// 如果是投播模式,使用 CastController 播放下一首
|
|
|
- if (this.castControllerWrapper && this.isCastPlaying) {
|
|
|
+ if (this.castControllerWrapper) {
|
|
|
console.info('heanup playNext', '使用 CastController 播放下一首');
|
|
|
try {
|
|
|
- // 传入最新的歌曲列表、索引和 videoUrl
|
|
|
- await this.castControllerWrapper.playNext(this.songList, this.curIndex, this.videoUrl);
|
|
|
+ const nextDuration = this.getSongDurationMs(this.currentSong);
|
|
|
+ if (nextDuration > 0) {
|
|
|
+ this.duration = nextDuration;
|
|
|
+ this.durationTime = Math.floor(nextDuration / 1000);
|
|
|
+ this.durationStringTime = secondToTime(this.durationTime);
|
|
|
+ this.totalTime = this.stringForTime(nextDuration);
|
|
|
+ this.avSessionController.setAVMetadataMusic(this.currentSong, nextDuration, this.lyricContent);
|
|
|
+ }
|
|
|
+ this.updateCastProgress(0);
|
|
|
+ await this.castControllerWrapper.playNext(this.songList, this.curIndex, this.videoUrl, nextDuration);
|
|
|
this.isCastPlaying = this.castControllerWrapper.getIsCastPlaying();
|
|
|
console.info('heanup playNext', 'CastController 播放下一首成功');
|
|
|
return;
|
|
|
@@ -15357,12 +15381,25 @@ export struct LocalMusic {
|
|
|
this.name = this.songList[this.curIndex].name
|
|
|
this.artist = this.songList[this.curIndex].artist
|
|
|
|
|
|
- // 如果是投播模式,需要为投播设备准备上一首
|
|
|
- if (this.castController && this.isCastPlaying) {
|
|
|
+ // 如果是投播模式,使用 CastController 切换上一首
|
|
|
+ if (this.castControllerWrapper) {
|
|
|
Logger.info('heanup playPrevious', '投播模式播放上一首,不调用本地stop()');
|
|
|
- this.initQueueItem();
|
|
|
- await this.prepare();
|
|
|
- // 投播模式下不需要调用本地的 startPlayOrResumePlay
|
|
|
+ try {
|
|
|
+ const prevDuration = this.getSongDurationMs(this.currentSong);
|
|
|
+ if (prevDuration > 0) {
|
|
|
+ this.duration = prevDuration;
|
|
|
+ this.durationTime = Math.floor(prevDuration / 1000);
|
|
|
+ this.durationStringTime = secondToTime(this.durationTime);
|
|
|
+ this.totalTime = this.stringForTime(prevDuration);
|
|
|
+ this.avSessionController.setAVMetadataMusic(this.currentSong, prevDuration, this.lyricContent);
|
|
|
+ }
|
|
|
+ this.updateCastProgress(0);
|
|
|
+ await this.castControllerWrapper.playPrevious(this.songList, this.curIndex, this.videoUrl, prevDuration);
|
|
|
+ this.isCastPlaying = this.castControllerWrapper.getIsCastPlaying();
|
|
|
+ } catch (error) {
|
|
|
+ Logger.error('heanup playPrevious', `CastController 播放上一首失败: ${error}`);
|
|
|
+ this.isCastPlaying = false;
|
|
|
+ }
|
|
|
this.cover = this.songList[this.curIndex].pixelMapPath;
|
|
|
return;
|
|
|
}
|