|
|
@@ -9591,6 +9591,7 @@ export struct LocalMusic {
|
|
|
@State isYesFull: boolean = false
|
|
|
private seekValue: number = 0
|
|
|
@State isVideoLock: boolean = false; // Whether the video playback is locked
|
|
|
+ private preloadNextRandomIndex: number = -1; // 预缓存的随机下一首索引
|
|
|
eventHub = getContext().eventHub;
|
|
|
//投播组件
|
|
|
private avSessionController: AvSessionController = AvSessionController.getInstance(false);
|
|
|
@@ -10237,9 +10238,11 @@ export struct LocalMusic {
|
|
|
else {
|
|
|
this.isSeekTo = true;
|
|
|
this.mDestroyPage = false;
|
|
|
- this.showLoadIng();
|
|
|
+ // 只有播放网盘歌曲时才显示转圈圈
|
|
|
+ if (this.currentSong && isRemoteCloudType(this.currentSong.type)) {
|
|
|
+ this.showLoadIng();
|
|
|
+ }
|
|
|
this.seekTo(position + "");
|
|
|
- this.isSeekTo = false;
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
@@ -10461,16 +10464,19 @@ export struct LocalMusic {
|
|
|
.layoutWeight(1)
|
|
|
.enabled(this.slideEnable)
|
|
|
.onChange((value: number, mode: SliderChangeMode) => {
|
|
|
- // if (mode == 2) {
|
|
|
+
|
|
|
+
|
|
|
this.isSeekTo = true;
|
|
|
this.mDestroyPage = false;
|
|
|
- this.showLoadIng();
|
|
|
+ // 只有播放网盘歌曲时才显示转圈圈
|
|
|
+ if (this.currentSong && isRemoteCloudType(this.currentSong.type)) {
|
|
|
+ this.showLoadIng();
|
|
|
+ }
|
|
|
LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
|
|
|
let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
|
|
|
this.seekTo(seekValue + "");
|
|
|
// this.setProgress()
|
|
|
LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
|
|
|
- this.isSeekTo = false;
|
|
|
// }
|
|
|
})
|
|
|
|
|
|
@@ -10740,15 +10746,18 @@ export struct LocalMusic {
|
|
|
.enabled(this.slideEnable)
|
|
|
.onChange((value: number, mode: SliderChangeMode) => {
|
|
|
// if (mode == 2) {
|
|
|
+
|
|
|
this.isSeekTo = true;
|
|
|
this.mDestroyPage = false;
|
|
|
- this.showLoadIng();
|
|
|
+ // 只有播放网盘歌曲时才显示转圈圈
|
|
|
+ if (this.currentSong && isRemoteCloudType(this.currentSong.type)) {
|
|
|
+ this.showLoadIng();
|
|
|
+ }
|
|
|
LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
|
|
|
let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
|
|
|
this.seekTo(seekValue + "");
|
|
|
// this.setProgress()
|
|
|
LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
|
|
|
- this.isSeekTo = false;
|
|
|
// }
|
|
|
})
|
|
|
Text(this.totalTime)
|
|
|
@@ -13116,8 +13125,11 @@ export struct LocalMusic {
|
|
|
this.startPlay(startOffset)
|
|
|
}
|
|
|
|
|
|
- // 提前缓存下一首
|
|
|
- void this.preloadNextSongInternal();
|
|
|
+ // 仅当前播放的是网盘歌曲时,才提前缓存下一首
|
|
|
+ // 排除用户拖动进度条的情况
|
|
|
+ if (this.currentSong && isRemoteCloudType(this.currentSong.type) && !this.isSeekTo) {
|
|
|
+ void this.preloadNextSongInternal();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
startPlay(startOffset?:number) {
|
|
|
@@ -13799,7 +13811,13 @@ export struct LocalMusic {
|
|
|
onSeekComplete: () => {
|
|
|
LogUtils.getInstance().LOGI("OnSeekCompleteListener-->go");
|
|
|
console.info('onecold startPlayOrResumePlay 10643')
|
|
|
- that.startPlayOrResumePlay();
|
|
|
+ // seek 完成,延迟恢复播放,确保 ijkplayer 内部状态完全稳定
|
|
|
+ setTimeout(() => {
|
|
|
+ // seek 完成,隐藏转圈圈并重置标志
|
|
|
+ that.hideLoadIng();
|
|
|
+ that.isSeekTo = false;
|
|
|
+ that.startPlayOrResumePlay();
|
|
|
+ }, 200); // 延迟200ms,确保ijkplayer内部状态稳定
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -14574,7 +14592,21 @@ export struct LocalMusic {
|
|
|
|
|
|
// 内部方法:提前缓存下一首
|
|
|
private async preloadNextSongInternal(): Promise<void> {
|
|
|
- await preloadNextSongIfNeeded(this.songList, this.curIndex, this.playType);
|
|
|
+ // 随机模式下传递已播放索引集合
|
|
|
+ if (this.playType === 3) {
|
|
|
+ this.preloadNextRandomIndex = await preloadNextSongIfNeeded(
|
|
|
+ this.songList,
|
|
|
+ this.curIndex,
|
|
|
+ this.playType,
|
|
|
+ this.playedIndices
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ this.preloadNextRandomIndex = await preloadNextSongIfNeeded(
|
|
|
+ this.songList,
|
|
|
+ this.curIndex,
|
|
|
+ this.playType
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 存储已播放的歌曲索引
|
|
|
@@ -14587,28 +14619,41 @@ export struct LocalMusic {
|
|
|
// }
|
|
|
if (ArrayUtil.isNotEmpty(this.songList)) {
|
|
|
if (this.songList.length > 3) {
|
|
|
- // 如果所有歌曲都播放过一次,清空已播放索引集合
|
|
|
- if (this.playedIndices.size === this.songList.length) {
|
|
|
- this.playedIndices.clear();
|
|
|
- }
|
|
|
+ // 优先使用预缓存的随机索引(仅网盘播放时)
|
|
|
+ const nextSong = this.songList[this.preloadNextRandomIndex >= 0 ? this.preloadNextRandomIndex : 0];
|
|
|
+ const isNextRemote = nextSong && isRemoteCloudType(nextSong.type);
|
|
|
+ const isCurrentRemote = this.currentSong && isRemoteCloudType(this.currentSong.type);
|
|
|
+
|
|
|
+ if (this.preloadNextRandomIndex >= 0 && this.preloadNextRandomIndex < this.songList.length && isNextRemote && isCurrentRemote) {
|
|
|
+ Logger.info('heanup randomPlay', `使用预缓存的随机索引: ${this.preloadNextRandomIndex} (网盘播放)`);
|
|
|
+ this.curIndex = this.preloadNextRandomIndex;
|
|
|
+ this.playedIndices.add(this.curIndex);
|
|
|
+ this.preloadNextRandomIndex = -1; // 重置预缓存索引
|
|
|
+ } else {
|
|
|
+ // 如果没有预缓存索引,则正常随机选择
|
|
|
+ // 如果所有歌曲都播放过一次,清空已播放索引集合
|
|
|
+ if (this.playedIndices.size === this.songList.length) {
|
|
|
+ this.playedIndices.clear();
|
|
|
+ }
|
|
|
|
|
|
- // 随机选择一个未播放的歌曲索引
|
|
|
- let newIndex: number;
|
|
|
- // 添加超时机制防止无限循环
|
|
|
- let attempt = 0;
|
|
|
- const maxAttempts = 100; // 根据需求调整
|
|
|
- do {
|
|
|
- newIndex = RandomUtil.getRandomNumber(0, this.songList.length - 1);
|
|
|
- attempt++;
|
|
|
- } while (this.playedIndices.has(newIndex) && attempt < maxAttempts);
|
|
|
+ // 随机选择一个未播放的歌曲索引
|
|
|
+ let newIndex: number;
|
|
|
+ // 添加超时机制防止无限循环
|
|
|
+ let attempt = 0;
|
|
|
+ const maxAttempts = 100; // 根据需求调整
|
|
|
+ do {
|
|
|
+ newIndex = RandomUtil.getRandomNumber(0, this.songList.length - 1);
|
|
|
+ attempt++;
|
|
|
+ } while (this.playedIndices.has(newIndex) && attempt < maxAttempts);
|
|
|
|
|
|
- if (attempt >= maxAttempts) {
|
|
|
- // 处理无法找到新索引的情况(如随机选择或按顺序播放)
|
|
|
- newIndex = Math.floor(Math.random() * this.songList.length);
|
|
|
- }
|
|
|
+ if (attempt >= maxAttempts) {
|
|
|
+ // 处理无法找到新索引的情况(如随机选择或按顺序播放)
|
|
|
+ newIndex = Math.floor(Math.random() * this.songList.length);
|
|
|
+ }
|
|
|
|
|
|
- this.curIndex = newIndex;
|
|
|
- this.playedIndices.add(newIndex);
|
|
|
+ this.curIndex = newIndex;
|
|
|
+ this.playedIndices.add(newIndex);
|
|
|
+ }
|
|
|
} else {
|
|
|
// 当歌曲数量小于或等于3时,直接播放下一首
|
|
|
if (this.curIndex == this.songList.length - 1) {
|