|
@@ -361,9 +361,9 @@ export struct LocalMusic {
|
|
|
.setOnRightClickListener(() => {
|
|
.setOnRightClickListener(() => {
|
|
|
this.showSheelDialog()
|
|
this.showSheelDialog()
|
|
|
})
|
|
})
|
|
|
- // .setOnTitleClickListener(() => {
|
|
|
|
|
- // this.showPupDialog()
|
|
|
|
|
- // })
|
|
|
|
|
|
|
+ // .setOnTitleClickListener(() => {
|
|
|
|
|
+ // this.showPupDialog()
|
|
|
|
|
+ // })
|
|
|
.setOnLeftClickListener(() => {
|
|
.setOnLeftClickListener(() => {
|
|
|
this.doSwipBack()
|
|
this.doSwipBack()
|
|
|
})
|
|
})
|
|
@@ -434,36 +434,36 @@ export struct LocalMusic {
|
|
|
private async initUnifiedPlayerService(): Promise<void> {
|
|
private async initUnifiedPlayerService(): Promise<void> {
|
|
|
try {
|
|
try {
|
|
|
await this.unifiedPlayerService.initialize(this.context);
|
|
await this.unifiedPlayerService.initialize(this.context);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 等待数据恢复完成后再获取播放列表
|
|
// 等待数据恢复完成后再获取播放列表
|
|
|
LogUtils.getInstance().LOGI('LocalMusic: Waiting for UnifiedPlayerService data restoration...');
|
|
LogUtils.getInstance().LOGI('LocalMusic: Waiting for UnifiedPlayerService data restoration...');
|
|
|
const dataRestored: boolean = await this.unifiedPlayerService.waitForDataRestoration(5000);
|
|
const dataRestored: boolean = await this.unifiedPlayerService.waitForDataRestoration(5000);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (!dataRestored) {
|
|
if (!dataRestored) {
|
|
|
LogUtils.getInstance().LOGI('LocalMusic: Data restoration timeout, but proceeding with initialization');
|
|
LogUtils.getInstance().LOGI('LocalMusic: Data restoration timeout, but proceeding with initialization');
|
|
|
} else {
|
|
} else {
|
|
|
LogUtils.getInstance().LOGI('LocalMusic: Data restoration completed successfully');
|
|
LogUtils.getInstance().LOGI('LocalMusic: Data restoration completed successfully');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 从UnifiedPlayerService恢复播放列表和状态
|
|
// 从UnifiedPlayerService恢复播放列表和状态
|
|
|
const restoredPlaylist = this.unifiedPlayerService.getPlaylist();
|
|
const restoredPlaylist = this.unifiedPlayerService.getPlaylist();
|
|
|
const restoredIndex = this.unifiedPlayerService.getCurrentIndex();
|
|
const restoredIndex = this.unifiedPlayerService.getCurrentIndex();
|
|
|
const restoredSong = this.unifiedPlayerService.getCurrentSong();
|
|
const restoredSong = this.unifiedPlayerService.getCurrentSong();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (ArrayUtil.isNotEmpty(restoredPlaylist)) {
|
|
if (ArrayUtil.isNotEmpty(restoredPlaylist)) {
|
|
|
// 恢复播放列表到LocalMusic
|
|
// 恢复播放列表到LocalMusic
|
|
|
this.songList = restoredPlaylist;
|
|
this.songList = restoredPlaylist;
|
|
|
this.curIndex = restoredIndex;
|
|
this.curIndex = restoredIndex;
|
|
|
this.currentSong = restoredSong || undefined;
|
|
this.currentSong = restoredSong || undefined;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 同步到AppStorage
|
|
// 同步到AppStorage
|
|
|
AppStorage.setOrCreate('songList', this.songList);
|
|
AppStorage.setOrCreate('songList', this.songList);
|
|
|
AppStorage.setOrCreate('currIndex', this.curIndex);
|
|
AppStorage.setOrCreate('currIndex', this.curIndex);
|
|
|
AppStorage.setOrCreate('currentSong', this.currentSong);
|
|
AppStorage.setOrCreate('currentSong', this.currentSong);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 更新UI数据源
|
|
// 更新UI数据源
|
|
|
this.sonDataSource.pushArrayData(this.songList);
|
|
this.sonDataSource.pushArrayData(this.songList);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 如果有当前歌曲,更新UI显示
|
|
// 如果有当前歌曲,更新UI显示
|
|
|
if (this.currentSong) {
|
|
if (this.currentSong) {
|
|
|
this.videoUrl = this.currentSong.filePath;
|
|
this.videoUrl = this.currentSong.filePath;
|
|
@@ -471,7 +471,7 @@ export struct LocalMusic {
|
|
|
this.artist = this.currentSong.artist;
|
|
this.artist = this.currentSong.artist;
|
|
|
this.cover = this.currentSong.pixelMapPath;
|
|
this.cover = this.currentSong.pixelMapPath;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic: Restored playlist from UnifiedPlayerService - ${this.songList.length} songs, index ${this.curIndex}, current song: ${this.currentSong?.name || 'null'}`);
|
|
LogUtils.getInstance().LOGI(`LocalMusic: Restored playlist from UnifiedPlayerService - ${this.songList.length} songs, index ${this.curIndex}, current song: ${this.currentSong?.name || 'null'}`);
|
|
|
} else {
|
|
} else {
|
|
|
LogUtils.getInstance().LOGI('LocalMusic: No playlist restored from UnifiedPlayerService, songList length = ' + this.songList.length);
|
|
LogUtils.getInstance().LOGI('LocalMusic: No playlist restored from UnifiedPlayerService, songList length = ' + this.songList.length);
|
|
@@ -481,25 +481,25 @@ export struct LocalMusic {
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic: Set existing playlist to UnifiedPlayerService - ${this.songList.length} songs`);
|
|
LogUtils.getInstance().LOGI(`LocalMusic: Set existing playlist to UnifiedPlayerService - ${this.songList.length} songs`);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 添加状态监听器,保持UI同步
|
|
// 添加状态监听器,保持UI同步
|
|
|
class LocalMusicStateListener implements PlayerStateListener {
|
|
class LocalMusicStateListener implements PlayerStateListener {
|
|
|
private localMusic: LocalMusic;
|
|
private localMusic: LocalMusic;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
constructor(localMusic: LocalMusic) {
|
|
constructor(localMusic: LocalMusic) {
|
|
|
this.localMusic = localMusic;
|
|
this.localMusic = localMusic;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
onStateChanged(state: PlayerState): void {
|
|
onStateChanged(state: PlayerState): void {
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic: StateListener triggered - isPlaying: ${state.isPlaying}, isPaused: ${state.isPaused}`);
|
|
LogUtils.getInstance().LOGI(`LocalMusic: StateListener triggered - isPlaying: ${state.isPlaying}, isPaused: ${state.isPaused}`);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 直接使用状态模型的状态,这是最权威的状态源
|
|
// 直接使用状态模型的状态,这是最权威的状态源
|
|
|
const isPlaying = state.isPlaying;
|
|
const isPlaying = state.isPlaying;
|
|
|
const isPaused = state.isPaused;
|
|
const isPaused = state.isPaused;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 同步播放状态到LocalMusic的UI状态
|
|
// 同步播放状态到LocalMusic的UI状态
|
|
|
const previousStatus: PlayStatus = this.localMusic.CONTROL_PlayStatus;
|
|
const previousStatus: PlayStatus = this.localMusic.CONTROL_PlayStatus;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 根据状态模型确定UI状态
|
|
// 根据状态模型确定UI状态
|
|
|
if (isPlaying) {
|
|
if (isPlaying) {
|
|
|
this.localMusic.CONTROL_PlayStatus = PlayStatus.PLAY;
|
|
this.localMusic.CONTROL_PlayStatus = PlayStatus.PLAY;
|
|
@@ -508,17 +508,17 @@ export struct LocalMusic {
|
|
|
} else {
|
|
} else {
|
|
|
this.localMusic.CONTROL_PlayStatus = PlayStatus.INIT;
|
|
this.localMusic.CONTROL_PlayStatus = PlayStatus.INIT;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 更新播放状态相关的UI
|
|
// 更新播放状态相关的UI
|
|
|
this.localMusic.setIsPlaying(isPlaying);
|
|
this.localMusic.setIsPlaying(isPlaying);
|
|
|
this.localMusic.updateSessionPlayState(isPlaying);
|
|
this.localMusic.updateSessionPlayState(isPlaying);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic: State sync - Previous: ${previousStatus}, New: ${this.localMusic.CONTROL_PlayStatus}, isPlaying: ${isPlaying}`);
|
|
LogUtils.getInstance().LOGI(`LocalMusic: State sync - Previous: ${previousStatus}, New: ${this.localMusic.CONTROL_PlayStatus}, isPlaying: ${isPlaying}`);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 强制触发UI更新,无论状态是否变化
|
|
// 强制触发UI更新,无论状态是否变化
|
|
|
this.localMusic.playChange();
|
|
this.localMusic.playChange();
|
|
|
this.localMusic.watchStatus();
|
|
this.localMusic.watchStatus();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 更新动画状态
|
|
// 更新动画状态
|
|
|
if (isPlaying) {
|
|
if (isPlaying) {
|
|
|
this.localMusic.animationState = AnimationStatus.Running;
|
|
this.localMusic.animationState = AnimationStatus.Running;
|
|
@@ -527,22 +527,22 @@ export struct LocalMusic {
|
|
|
this.localMusic.animationState = AnimationStatus.Paused;
|
|
this.localMusic.animationState = AnimationStatus.Paused;
|
|
|
this.localMusic.mDestroyPage = true;
|
|
this.localMusic.mDestroyPage = true;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic: UI update completed - CONTROL_PlayStatus: ${this.localMusic.CONTROL_PlayStatus}, globalIsPlaying: ${this.localMusic.isPlaying}`);
|
|
LogUtils.getInstance().LOGI(`LocalMusic: UI update completed - CONTROL_PlayStatus: ${this.localMusic.CONTROL_PlayStatus}, globalIsPlaying: ${this.localMusic.isPlaying}`);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 同步播放模式
|
|
// 同步播放模式
|
|
|
if (this.localMusic.playType !== state.playMode) {
|
|
if (this.localMusic.playType !== state.playMode) {
|
|
|
this.localMusic.playType = state.playMode;
|
|
this.localMusic.playType = state.playMode;
|
|
|
this.localMusic.setCurrentPlayMode();
|
|
this.localMusic.setCurrentPlayMode();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 同步音量和速度
|
|
// 同步音量和速度
|
|
|
this.localMusic.volume = state.volume;
|
|
this.localMusic.volume = state.volume;
|
|
|
this.localMusic.playSpeed = state.speed;
|
|
this.localMusic.playSpeed = state.speed;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic: State synchronized - isPlaying=${state.isPlaying}, mode=${state.playMode}`);
|
|
LogUtils.getInstance().LOGI(`LocalMusic: State synchronized - isPlaying=${state.isPlaying}, mode=${state.playMode}`);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
onSongChanged(song: VideoItem): void {
|
|
onSongChanged(song: VideoItem): void {
|
|
|
console.log(`Heanup onSongChanged - 开始处理歌曲切换: ${song.name}`);
|
|
console.log(`Heanup onSongChanged - 开始处理歌曲切换: ${song.name}`);
|
|
|
console.log(`Heanup onSongChanged - 切换前 oldSeconds: ${this.localMusic.oldSeconds}, currentTime: ${this.localMusic.currentTime}`);
|
|
console.log(`Heanup onSongChanged - 切换前 oldSeconds: ${this.localMusic.oldSeconds}, currentTime: ${this.localMusic.currentTime}`);
|
|
@@ -716,6 +716,7 @@ export struct LocalMusic {
|
|
|
this.saveVideoDatas([eventData.data?.message], true)
|
|
this.saveVideoDatas([eventData.data?.message], true)
|
|
|
|
|
|
|
|
});
|
|
});
|
|
|
|
|
+ this.setAvSessionListener();
|
|
|
|
|
|
|
|
//侧滑广播接收时间
|
|
//侧滑广播接收时间
|
|
|
let eventUpdateSwipeBack: emitter.InnerEvent = { eventId: 888 }
|
|
let eventUpdateSwipeBack: emitter.InnerEvent = { eventId: 888 }
|
|
@@ -807,7 +808,7 @@ export struct LocalMusic {
|
|
|
// 安全地注册窗口大小变化监听器
|
|
// 安全地注册窗口大小变化监听器
|
|
|
if (this.windowClass) {
|
|
if (this.windowClass) {
|
|
|
this.windowClass.on('windowSizeChange', (size) => {
|
|
this.windowClass.on('windowSizeChange', (size) => {
|
|
|
- LogUtil.info('onecold windowSizeChange')
|
|
|
|
|
|
|
+ LogUtil.info('onecold windowSizeChange')
|
|
|
this.doChangeBarHeight()
|
|
this.doChangeBarHeight()
|
|
|
let viewWidth = px2vp(size.width);
|
|
let viewWidth = px2vp(size.width);
|
|
|
let viewHeight = px2vp(size.height);
|
|
let viewHeight = px2vp(size.height);
|
|
@@ -1153,13 +1154,7 @@ export struct LocalMusic {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 清理AvSession卡片监听器
|
|
|
|
|
- try {
|
|
|
|
|
- this.avSessionWidgetListener.destroy();
|
|
|
|
|
- LogUtils.getInstance().LOGI('AvSession widget listener destroyed successfully');
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- LogUtils.getInstance().error(`Error during AvSession widget listener cleanup: ${error}`);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.avSessionController.unregisterSessionListener();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async getSortedFiles(curPath: string, isWorkerPost?: boolean, destPath?: string, isOpen?: boolean) {
|
|
async getSortedFiles(curPath: string, isWorkerPost?: boolean, destPath?: string, isOpen?: boolean) {
|
|
@@ -2899,7 +2894,7 @@ export struct LocalMusic {
|
|
|
Row() {
|
|
Row() {
|
|
|
Column(){
|
|
Column(){
|
|
|
Text(item.md5Str?.includes('Lossless')?
|
|
Text(item.md5Str?.includes('Lossless')?
|
|
|
- Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
|
|
|
|
|
|
|
+ Utility.resourceToString(this.context,$r('app.string.lossless')):item.md5Str)//音质
|
|
|
.fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
|
|
.fontSize(this.twoFingerType == 1 ? 8 : this.twoFingerType == 2 ? 9 : 11)
|
|
|
.padding({ top: 3,right:6,left:6,bottom:3 })
|
|
.padding({ top: 3,right:6,left:6,bottom:3 })
|
|
|
.fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
|
|
.fontColor(this.currentSong?.filePath === item.filePath ? this.themeColor :
|
|
@@ -3177,7 +3172,7 @@ export struct LocalMusic {
|
|
|
.padding({ top: 8 })
|
|
.padding({ top: 8 })
|
|
|
.maxLines(1)
|
|
.maxLines(1)
|
|
|
.visibility(StrUtil.isEmpty(this.videoLocalList[0].year)||
|
|
.visibility(StrUtil.isEmpty(this.videoLocalList[0].year)||
|
|
|
- this.videoLocalList[0].year.includes(this.UNKONWN)
|
|
|
|
|
|
|
+ this.videoLocalList[0].year.includes(this.UNKONWN)
|
|
|
?Visibility.None:Visibility.Visible)
|
|
?Visibility.None:Visibility.Visible)
|
|
|
.fontWeight(FontWeight.Bold)
|
|
.fontWeight(FontWeight.Bold)
|
|
|
.fontColor($r('app.color.text_color'))
|
|
.fontColor($r('app.color.text_color'))
|
|
@@ -3843,7 +3838,7 @@ export struct LocalMusic {
|
|
|
// if (this.isPhoneLan()) {
|
|
// if (this.isPhoneLan()) {
|
|
|
// this.setBarHeightHide(offset)
|
|
// this.setBarHeightHide(offset)
|
|
|
// } else
|
|
// } else
|
|
|
- if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
|
|
|
|
|
|
|
+ if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
|
|
|
(this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
|
|
(this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
|
|
|
this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
|
|
this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
|
|
|
if (this.isScrollHide) {
|
|
if (this.isScrollHide) {
|
|
@@ -3872,7 +3867,7 @@ export struct LocalMusic {
|
|
|
records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
|
|
records[i].getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
|
|
|
let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
|
|
let typeDescriptor = uniformTypeDescriptor.getTypeDescriptor(fileUriUds.fileType);
|
|
|
if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
|
|
if (typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.AUDIO)
|
|
|
- ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
|
|
|
|
|
|
|
+ ||typeDescriptor.belongsTo(uniformTypeDescriptor.UniformDataType.VIDEO)) {
|
|
|
this.targetFile = fileUriUds.oriUri;
|
|
this.targetFile = fileUriUds.oriUri;
|
|
|
this.saveVideoDatas([this.targetFile])
|
|
this.saveVideoDatas([this.targetFile])
|
|
|
hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
|
|
hilog.info(0x0000, 'Heanup', '当前targetFile:' + this.targetFile);
|
|
@@ -3987,7 +3982,7 @@ export struct LocalMusic {
|
|
|
}
|
|
}
|
|
|
.margin({ top: 2 ,right:6})
|
|
.margin({ top: 2 ,right:6})
|
|
|
.visibility((this.modeType == 3 && !this.isCanBack)||(this.modeType == 2 && !this.isCanBack)
|
|
.visibility((this.modeType == 3 && !this.isCanBack)||(this.modeType == 2 && !this.isCanBack)
|
|
|
- ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
|
|
|
|
|
|
|
+ ||(this.modeType == 0&&item.type==CommonConstants.TYPE_IS_DIR)? Visibility.None : Visibility.Visible)
|
|
|
Text(StrUtil.isEmpty(item.artist) ? item.duration: item.artist)
|
|
Text(StrUtil.isEmpty(item.artist) ? item.duration: item.artist)
|
|
|
.fontSize(11)
|
|
.fontSize(11)
|
|
|
.fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
|
|
.fontSize(this.twoFingerType == 1 ? 10 : this.twoFingerType == 2 ? 12 : 14)
|
|
@@ -4490,7 +4485,7 @@ export struct LocalMusic {
|
|
|
// if (this.isPhoneLan()) {
|
|
// if (this.isPhoneLan()) {
|
|
|
// this.setBarHeightHide(offset)
|
|
// this.setBarHeightHide(offset)
|
|
|
// } else
|
|
// } else
|
|
|
- if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
|
|
|
|
|
|
|
+ if (this.currentWidthBreakpoint !== WidthBreakpoint.WIDTH_SM ||
|
|
|
(this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
|
|
(this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_MD &&
|
|
|
this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
|
|
this.currentHeightBreakpoint !== HeightBreakpoint.HEIGHT_SM)) {
|
|
|
if (this.isScrollHide) {
|
|
if (this.isScrollHide) {
|
|
@@ -4507,7 +4502,7 @@ export struct LocalMusic {
|
|
|
return { offsetRemain: offset };
|
|
return { offsetRemain: offset };
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- //拖拽pc或者pad的用鼠标拖拽音乐和视频到List或Grid上自动导入视频
|
|
|
|
|
|
|
+ //拖拽pc或者pad的用鼠标拖拽音乐和视频到List或Grid上自动导入视频
|
|
|
.allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
|
|
.allowDrop([uniformTypeDescriptor.UniformDataType.AUDIO,uniformTypeDescriptor.UniformDataType.VIDEO])
|
|
|
.onDrop((event?: DragEvent) => {
|
|
.onDrop((event?: DragEvent) => {
|
|
|
try {
|
|
try {
|
|
@@ -6733,9 +6728,9 @@ export struct LocalMusic {
|
|
|
let neiqianLrc = ''
|
|
let neiqianLrc = ''
|
|
|
let lyContent = this.currentSong?.lyricContent
|
|
let lyContent = this.currentSong?.lyricContent
|
|
|
if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
|
|
if(lyContent&&StrUtil.isNotEmpty(lyContent)){//取数据库里面的歌词lyContent
|
|
|
- neiqianLrc = lyContent
|
|
|
|
|
|
|
+ neiqianLrc = lyContent
|
|
|
}else{
|
|
}else{
|
|
|
- neiqianLrc = LrcParser.getLyrics(this.videoUrl); //获取内嵌歌词
|
|
|
|
|
|
|
+ neiqianLrc = LrcParser.getLyrics(this.videoUrl); //获取内嵌歌词
|
|
|
}
|
|
}
|
|
|
if (StrUtil.isNotEmpty(neiqianLrc) && !isOnLineAndToast) {
|
|
if (StrUtil.isNotEmpty(neiqianLrc) && !isOnLineAndToast) {
|
|
|
console.log("onecold 找到内嵌歌词 neiqianLrc =" + neiqianLrc)
|
|
console.log("onecold 找到内嵌歌词 neiqianLrc =" + neiqianLrc)
|
|
@@ -9946,7 +9941,7 @@ export struct LocalMusic {
|
|
|
// 歌曲切换时,强制将播放位置重置为0,忽略服务报告的位置
|
|
// 歌曲切换时,强制将播放位置重置为0,忽略服务报告的位置
|
|
|
progress.currentPosition = 0;
|
|
progress.currentPosition = 0;
|
|
|
console.log(`Heanup 歌曲切换,强制progress.currentPosition为0`);
|
|
console.log(`Heanup 歌曲切换,强制progress.currentPosition为0`);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 立即返回,不更新进度,等待新歌曲开始播放
|
|
// 立即返回,不更新进度,等待新歌曲开始播放
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -9957,7 +9952,7 @@ export struct LocalMusic {
|
|
|
if (ijkPlayer && ijkPlayer.isPlaying()) {
|
|
if (ijkPlayer && ijkPlayer.isPlaying()) {
|
|
|
const currentPosition = ijkPlayer.getCurrentPosition();
|
|
const currentPosition = ijkPlayer.getCurrentPosition();
|
|
|
const duration = ijkPlayer.getDuration();
|
|
const duration = ijkPlayer.getDuration();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (duration > 0 && currentPosition >= 0) {
|
|
if (duration > 0 && currentPosition >= 0) {
|
|
|
// 更新进度条
|
|
// 更新进度条
|
|
|
this.slideEnable = true;
|
|
this.slideEnable = true;
|
|
@@ -9977,7 +9972,7 @@ export struct LocalMusic {
|
|
|
this.currentTime = this.stringForTime(currentPosition);
|
|
this.currentTime = this.stringForTime(currentPosition);
|
|
|
this.isCurrentTime = false;
|
|
this.isCurrentTime = false;
|
|
|
console.log(`Heanup 更新后 - oldSeconds: ${this.oldSeconds}, currentTime: ${this.currentTime}`)
|
|
console.log(`Heanup 更新后 - oldSeconds: ${this.oldSeconds}, currentTime: ${this.currentTime}`)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 继续执行后续的歌词更新等逻辑
|
|
// 继续执行后续的歌词更新等逻辑
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -10098,10 +10093,10 @@ export struct LocalMusic {
|
|
|
// 检查是否在切换后的冷却期内(切换后5秒内允许更大的时间跳跃)
|
|
// 检查是否在切换后的冷却期内(切换后5秒内允许更大的时间跳跃)
|
|
|
const timeSinceSwitch = this.lastSwitchTime ? Date.now() - this.lastSwitchTime : Number.MAX_VALUE;
|
|
const timeSinceSwitch = this.lastSwitchTime ? Date.now() - this.lastSwitchTime : Number.MAX_VALUE;
|
|
|
const isInCooldown = timeSinceSwitch < 5000; // 5秒冷却期
|
|
const isInCooldown = timeSinceSwitch < 5000; // 5秒冷却期
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 如果时间差值过大,根据情况处理
|
|
// 如果时间差值过大,根据情况处理
|
|
|
const timeDiff = Math.abs(seconds - this.oldSeconds);
|
|
const timeDiff = Math.abs(seconds - this.oldSeconds);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (timeDiff > 10) {
|
|
if (timeDiff > 10) {
|
|
|
// 如果在冷却期内,允许更大的时间跳跃(可能是新歌曲开始播放)
|
|
// 如果在冷却期内,允许更大的时间跳跃(可能是新歌曲开始播放)
|
|
|
if (isInCooldown) {
|
|
if (isInCooldown) {
|
|
@@ -10325,6 +10320,20 @@ export struct LocalMusic {
|
|
|
this.setCurrentPlayMode()
|
|
this.setCurrentPlayMode()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public async setAvSessionListener() {
|
|
|
|
|
+ if (!this.avSessionController) {
|
|
|
|
|
+ console.log('heanup setAvSessionListener error: avSessionController is null');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ this.avSessionController.getAvSession()?.on('fastForward', this.sessionFastForwardCallback);
|
|
|
|
|
+ this.avSessionController.getAvSession()?.on('rewind', this.sessionRewindCallback);
|
|
|
|
|
+ this.avSessionController.getAvSession()?.on('setLoopMode', this.sessionSetLoopModeCallback);
|
|
|
|
|
+ this.avSessionController.getAvSession()?.on('toggleFavorite', this.sessionToggleFavoriteCallback);
|
|
|
|
|
+ console.log('heanup setAvSessionListener');
|
|
|
|
|
+ this.avSessionController.getAvSession()?.on('outputDeviceChange', this.sessionOutputDeviceChange)
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private sessionSetLoopModeCallback = (mode: number) => {
|
|
private sessionSetLoopModeCallback = (mode: number) => {
|
|
|
ToastUtil.showToast('当前播放模式:' + mode)
|
|
ToastUtil.showToast('当前播放模式:' + mode)
|
|
|
Logger.info('onecold 当前播放模式= ' + mode)
|
|
Logger.info('onecold 当前播放模式= ' + mode)
|
|
@@ -10332,30 +10341,30 @@ export struct LocalMusic {
|
|
|
if (hmPlayMode >= 4) {
|
|
if (hmPlayMode >= 4) {
|
|
|
hmPlayMode = 0
|
|
hmPlayMode = 0
|
|
|
}
|
|
}
|
|
|
- if (hmPlayMode === 1) {
|
|
|
|
|
- this.setPlayModeViaService(1);
|
|
|
|
|
- ToastUtil.showToast('单曲循环')
|
|
|
|
|
- } else if (hmPlayMode === 0) {
|
|
|
|
|
- this.setPlayModeViaService(2);
|
|
|
|
|
- ToastUtil.showToast('单曲播完')
|
|
|
|
|
- } else if (hmPlayMode === 3) {
|
|
|
|
|
- this.setPlayModeViaService(3);
|
|
|
|
|
- ToastUtil.showToast('随机播放')
|
|
|
|
|
- } else if (hmPlayMode === 2) {
|
|
|
|
|
- this.setPlayModeViaService(0);
|
|
|
|
|
- ToastUtil.showToast('连续播放')
|
|
|
|
|
- }
|
|
|
|
|
- // 应用收到设置循环模式的指令后,应用自定下一个模式,切换完毕后通过AVPlaybackState上报切换后的LoopMode。
|
|
|
|
|
- let playBackState: avSession.AVPlaybackState = {
|
|
|
|
|
- loopMode: hmPlayMode,
|
|
|
|
|
- };
|
|
|
|
|
- this.avSessionController.getAvSession()?.setAVPlaybackState(playBackState).then(() => {
|
|
|
|
|
- console.info(`set setLoopMode AVPlaybackState successfully`);
|
|
|
|
|
- }).catch((err: BusinessError) => {
|
|
|
|
|
- console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if (hmPlayMode === 1) {
|
|
|
|
|
+ this.setPlayModeViaService(1);
|
|
|
|
|
+ ToastUtil.showToast('单曲循环')
|
|
|
|
|
+ } else if (hmPlayMode === 0) {
|
|
|
|
|
+ this.setPlayModeViaService(2);
|
|
|
|
|
+ ToastUtil.showToast('单曲播完')
|
|
|
|
|
+ } else if (hmPlayMode === 3) {
|
|
|
|
|
+ this.setPlayModeViaService(3);
|
|
|
|
|
+ ToastUtil.showToast('随机播放')
|
|
|
|
|
+ } else if (hmPlayMode === 2) {
|
|
|
|
|
+ this.setPlayModeViaService(0);
|
|
|
|
|
+ ToastUtil.showToast('连续播放')
|
|
|
}
|
|
}
|
|
|
|
|
+ PreferencesUtil.putSync('musicPlayType', this.playType)
|
|
|
|
|
+ // 应用收到设置循环模式的指令后,应用自定下一个模式,切换完毕后通过AVPlaybackState上报切换后的LoopMode。
|
|
|
|
|
+ let playBackState: avSession.AVPlaybackState = {
|
|
|
|
|
+ loopMode: hmPlayMode,
|
|
|
|
|
+ };
|
|
|
|
|
+ this.avSessionController.getAvSession()?.setAVPlaybackState(playBackState).then(() => {
|
|
|
|
|
+ console.info(`set setLoopMode AVPlaybackState successfully`);
|
|
|
|
|
+ }).catch((err: BusinessError) => {
|
|
|
|
|
+ console.error(`Failed to setLoopMode set AVPlaybackState. Code: ${err.code}, message: ${err.message}`);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
setCurrentPlayMode() {
|
|
setCurrentPlayMode() {
|
|
|
if (!this.avSessionController) {
|
|
if (!this.avSessionController) {
|
|
@@ -10399,11 +10408,12 @@ export struct LocalMusic {
|
|
|
let playbackState: avSession.AVPlaybackState = {
|
|
let playbackState: avSession.AVPlaybackState = {
|
|
|
isFavorite: !this.isFac,
|
|
isFavorite: !this.isFac,
|
|
|
};
|
|
};
|
|
|
- this.avSessionController.getAvSession()?.setAVPlaybackState(playbackState).then(() => {
|
|
|
|
|
- console.info(`SetAVPlaybackState successfully`);
|
|
|
|
|
- }).catch((err: BusinessError) => {
|
|
|
|
|
- console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // this.avSessionController.setAvSessionPlayState(playbackState);
|
|
|
|
|
+ // this.avSessionController.getAvSession()?.setAVPlaybackState(playbackState).then(() => {
|
|
|
|
|
+ // console.info(`SetAVPlaybackState successfully`+assetId+this.isFac);
|
|
|
|
|
+ // }).catch((err: BusinessError) => {
|
|
|
|
|
+ // console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
|
|
|
|
|
+ // });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
private sessionOutputDeviceChange = async (connectState: avSession.ConnectionState,
|
|
private sessionOutputDeviceChange = async (connectState: avSession.ConnectionState,
|
|
@@ -10629,21 +10639,6 @@ export struct LocalMusic {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private sessionPlayCallback = (): void => {
|
|
|
|
|
- LogUtils.getInstance().LOGI("LocalMusic: System play button pressed");
|
|
|
|
|
- // 直接调用UnifiedPlayerService的方法,而不是LocalMusic的playOrPause
|
|
|
|
|
- this.unifiedPlayerService.startPlayOrResumePlay().catch((error: Error) => {
|
|
|
|
|
- LogUtils.getInstance().LOGI(`LocalMusic: System play command failed: ${error}`);
|
|
|
|
|
- });
|
|
|
|
|
- };
|
|
|
|
|
- private sessionPauseCallback = (): void => {
|
|
|
|
|
- LogUtils.getInstance().LOGI("LocalMusic: System pause button pressed");
|
|
|
|
|
- // 直接调用UnifiedPlayerService的方法,而不是LocalMusic的playOrPause
|
|
|
|
|
- this.unifiedPlayerService.pause().catch((error: Error) => {
|
|
|
|
|
- LogUtils.getInstance().LOGI(`LocalMusic: System pause command failed: ${error}`);
|
|
|
|
|
- });
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
private playOrPause() {
|
|
private playOrPause() {
|
|
|
if (!this.debounce()) {
|
|
if (!this.debounce()) {
|
|
|
return;
|
|
return;
|
|
@@ -10657,15 +10652,6 @@ export struct LocalMusic {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private sessionPlayNextCallback = (): void => {
|
|
|
|
|
- this.playNext()
|
|
|
|
|
- };
|
|
|
|
|
- private sessionPlayPreviousCallback = (): void => {
|
|
|
|
|
- this.playPrevious()
|
|
|
|
|
- };
|
|
|
|
|
- private sessionStopCallback = (): void => {
|
|
|
|
|
- this.stop()
|
|
|
|
|
- };
|
|
|
|
|
private sessionFastForwardCallback = (time?: number) => {
|
|
private sessionFastForwardCallback = (time?: number) => {
|
|
|
if (!time) {
|
|
if (!time) {
|
|
|
return;
|
|
return;
|
|
@@ -10731,11 +10717,11 @@ export struct LocalMusic {
|
|
|
if (seeTime < 0) {
|
|
if (seeTime < 0) {
|
|
|
seeTime = 0;
|
|
seeTime = 0;
|
|
|
} else if (seeTime > this.duration) {
|
|
} else if (seeTime > this.duration) {
|
|
|
- seeTime = this.duration;
|
|
|
|
|
- }
|
|
|
|
|
- Logger.info('onecold seeTime= ' + seeTime)
|
|
|
|
|
- this.setSeekToActionProgress(seeTime)
|
|
|
|
|
- this.seekTo(seeTime + "")
|
|
|
|
|
|
|
+ seeTime = this.duration;
|
|
|
|
|
+ }
|
|
|
|
|
+ Logger.info('onecold seeTime= ' + seeTime)
|
|
|
|
|
+ this.setSeekToActionProgress(seeTime)
|
|
|
|
|
+ this.seekTo(seeTime + "")
|
|
|
};
|
|
};
|
|
|
private sessionSeekCallback = (seekTime: number) => {
|
|
private sessionSeekCallback = (seekTime: number) => {
|
|
|
const curPosition: number = this.unifiedPlayerService.getCurrentPosition()
|
|
const curPosition: number = this.unifiedPlayerService.getCurrentPosition()
|
|
@@ -10968,18 +10954,18 @@ export struct LocalMusic {
|
|
|
this.changeImageAnimation();
|
|
this.changeImageAnimation();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
LogUtils.getInstance().LOGI("LocalMusic: playNext completed via UnifiedPlayerService");
|
|
LogUtils.getInstance().LOGI("LocalMusic: playNext completed via UnifiedPlayerService");
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic playNext error: ${error}`);
|
|
LogUtils.getInstance().LOGI(`LocalMusic playNext error: ${error}`);
|
|
|
ToastUtil.showToast(`切换下一首失败: ${error}`);
|
|
ToastUtil.showToast(`切换下一首失败: ${error}`);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 错误处理:回退到原有逻辑
|
|
// 错误处理:回退到原有逻辑
|
|
|
this.fallbackPlayNext();
|
|
this.fallbackPlayNext();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 回退到原有的playNext逻辑
|
|
// 回退到原有的playNext逻辑
|
|
|
private fallbackPlayNext() {
|
|
private fallbackPlayNext() {
|
|
|
if (ArrayUtil.isNotEmpty(this.songList)) {
|
|
if (ArrayUtil.isNotEmpty(this.songList)) {
|
|
@@ -10988,10 +10974,10 @@ export struct LocalMusic {
|
|
|
} else {
|
|
} else {
|
|
|
this.curIndex++;
|
|
this.curIndex++;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
AppStorage.setOrCreate('songList', this.songList);
|
|
AppStorage.setOrCreate('songList', this.songList);
|
|
|
AppStorage.setOrCreate('currIndex', this.curIndex);
|
|
AppStorage.setOrCreate('currIndex', this.curIndex);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
this.CONTROL_PlayStatus = PlayStatus.INIT;
|
|
this.CONTROL_PlayStatus = PlayStatus.INIT;
|
|
|
this.stop();
|
|
this.stop();
|
|
|
this.currentSong = this.songList[this.curIndex]
|
|
this.currentSong = this.songList[this.curIndex]
|
|
@@ -11117,24 +11103,24 @@ export struct LocalMusic {
|
|
|
if (!this.debounce()) {
|
|
if (!this.debounce()) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
if (this.playType == 3) { //3:随机播放的上一首应该应该播放历史记录的第二首
|
|
if (this.playType == 3) { //3:随机播放的上一首应该应该播放历史记录的第二首
|
|
|
this.randomModePlayFromHistory()
|
|
this.randomModePlayFromHistory()
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (ArrayUtil.isNotEmpty(this.songList)) {
|
|
if (ArrayUtil.isNotEmpty(this.songList)) {
|
|
|
// 确保播放列表已同步到UnifiedPlayerService
|
|
// 确保播放列表已同步到UnifiedPlayerService
|
|
|
this.unifiedPlayerService.setPlaylist(this.songList, this.curIndex);
|
|
this.unifiedPlayerService.setPlaylist(this.songList, this.curIndex);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 使用UnifiedPlayerService播放上一首
|
|
// 使用UnifiedPlayerService播放上一首
|
|
|
await this.unifiedPlayerService.playPrevious();
|
|
await this.unifiedPlayerService.playPrevious();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 更新本地状态以保持UI同步
|
|
// 更新本地状态以保持UI同步
|
|
|
const currentIndex = this.unifiedPlayerService.getCurrentIndex();
|
|
const currentIndex = this.unifiedPlayerService.getCurrentIndex();
|
|
|
const currentSong = this.unifiedPlayerService.getCurrentSong();
|
|
const currentSong = this.unifiedPlayerService.getCurrentSong();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (currentSong) {
|
|
if (currentSong) {
|
|
|
this.curIndex = currentIndex;
|
|
this.curIndex = currentIndex;
|
|
|
this.currentSong = currentSong;
|
|
this.currentSong = currentSong;
|
|
@@ -11142,14 +11128,14 @@ export struct LocalMusic {
|
|
|
this.name = currentSong.name;
|
|
this.name = currentSong.name;
|
|
|
this.artist = currentSong.artist;
|
|
this.artist = currentSong.artist;
|
|
|
this.cover = currentSong.pixelMapPath;
|
|
this.cover = currentSong.pixelMapPath;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 重置时间显示状态,防止新歌曲时间显示被上一首歌曲的时间"卡住"
|
|
// 重置时间显示状态,防止新歌曲时间显示被上一首歌曲的时间"卡住"
|
|
|
this.oldSeconds = 0;
|
|
this.oldSeconds = 0;
|
|
|
this.currentTime = "00:00";
|
|
this.currentTime = "00:00";
|
|
|
this.lastSongPath = currentSong.filePath;
|
|
this.lastSongPath = currentSong.filePath;
|
|
|
this.justSwitched = true; // 标记歌曲刚刚切换
|
|
this.justSwitched = true; // 标记歌曲刚刚切换
|
|
|
console.log(`Heanup playPrevious - 重置时间显示状态: oldSeconds=${this.oldSeconds}, currentTime=${this.currentTime}`);
|
|
console.log(`Heanup playPrevious - 重置时间显示状态: oldSeconds=${this.oldSeconds}, currentTime=${this.currentTime}`);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 同步到AppStorage,确保卡片能获取到最新状态
|
|
// 同步到AppStorage,确保卡片能获取到最新状态
|
|
|
AppStorage.setOrCreate('songList', this.songList);
|
|
AppStorage.setOrCreate('songList', this.songList);
|
|
|
AppStorage.setOrCreate('currIndex', this.curIndex);
|
|
AppStorage.setOrCreate('currIndex', this.curIndex);
|
|
@@ -11158,17 +11144,17 @@ export struct LocalMusic {
|
|
|
this.changeImageAnimation();
|
|
this.changeImageAnimation();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
LogUtils.getInstance().LOGI("LocalMusic: playPrevious completed via UnifiedPlayerService");
|
|
LogUtils.getInstance().LOGI("LocalMusic: playPrevious completed via UnifiedPlayerService");
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
LogUtils.getInstance().LOGI(`LocalMusic playPrevious error: ${error}`);
|
|
LogUtils.getInstance().LOGI(`LocalMusic playPrevious error: ${error}`);
|
|
|
ToastUtil.showToast(`切换上一首失败: ${error}`);
|
|
ToastUtil.showToast(`切换上一首失败: ${error}`);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 错误处理:回退到原有逻辑
|
|
// 错误处理:回退到原有逻辑
|
|
|
this.fallbackPlayPrevious();
|
|
this.fallbackPlayPrevious();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 回退到原有的playPrevious逻辑
|
|
// 回退到原有的playPrevious逻辑
|
|
|
private fallbackPlayPrevious() {
|
|
private fallbackPlayPrevious() {
|
|
|
if (this.curIndex == 0) {
|
|
if (this.curIndex == 0) {
|
|
@@ -11610,82 +11596,6 @@ export struct LocalMusic {
|
|
|
// this.status = "广告加载中..."
|
|
// this.status = "广告加载中..."
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 展示Banner广告
|
|
|
|
|
- */
|
|
|
|
|
- // showBannerAd() {
|
|
|
|
|
- // if (!this.bannerAd) {
|
|
|
|
|
- // return
|
|
|
|
|
- // }
|
|
|
|
|
- // this.isShowAd = true
|
|
|
|
|
- // this.status = "已展示"
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 穿山甲广告代码结束
|
|
|
|
|
- */
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 初始化AvSession卡片监听器
|
|
|
|
|
- */
|
|
|
|
|
- private initAvSessionWidgetListener(): void {
|
|
|
|
|
- try {
|
|
|
|
|
- // 不需要在这里注册监听器,因为我们直接通过updateWidgetData更新数据
|
|
|
|
|
- // 避免循环调用和重复广播
|
|
|
|
|
- LogUtils.getInstance().LOGI('AvSession widget listener initialized successfully (no circular listener)');
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- LogUtils.getInstance().error(`Failed to initialize AvSession widget listener: ${error}`);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 广播AvSession状态到卡片
|
|
|
|
|
- */
|
|
|
|
|
- private broadcastAvSessionStateToWidget(widgetData: WidgetData): void {
|
|
|
|
|
- try {
|
|
|
|
|
- // 广播播放状态变化
|
|
|
|
|
- const statePublishInfo: commonEventManager.CommonEventPublishData = {
|
|
|
|
|
- data: JSON.stringify(widgetData)
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- commonEventManager.publish(PLAYER_STATE_CHANGED_EVENT, statePublishInfo, (err) => {
|
|
|
|
|
- if (err) {
|
|
|
|
|
- LogUtils.getInstance().error(`Failed to broadcast AvSession state: ${JSON.stringify(err)}`);
|
|
|
|
|
- } else {
|
|
|
|
|
- LogUtils.getInstance().LOGI('AvSession state broadcasted to widget successfully');
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 如果有歌曲信息变化,也广播歌曲变化事件
|
|
|
|
|
- if (widgetData.currentSong) {
|
|
|
|
|
- const songPublishInfo: commonEventManager.CommonEventPublishData = {
|
|
|
|
|
- data: JSON.stringify({ currentSong: widgetData.currentSong })
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- commonEventManager.publish(PLAYER_SONG_CHANGED_EVENT, songPublishInfo, (err) => {
|
|
|
|
|
- if (err) {
|
|
|
|
|
- LogUtils.getInstance().error(`Failed to broadcast song change: ${JSON.stringify(err)}`);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 如果有进度信息变化,也广播进度变化事件
|
|
|
|
|
- if (widgetData.progress) {
|
|
|
|
|
- const progressPublishInfo: commonEventManager.CommonEventPublishData = {
|
|
|
|
|
- data: JSON.stringify(widgetData.progress)
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- commonEventManager.publish(PLAYER_PROGRESS_CHANGED_EVENT, progressPublishInfo, (err) => {
|
|
|
|
|
- if (err) {
|
|
|
|
|
- LogUtils.getInstance().error(`Failed to broadcast progress change: ${JSON.stringify(err)}`);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- LogUtils.getInstance().error(`Failed to broadcast AvSession state to widget: ${error}`);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 节流广播进度更新
|
|
* 节流广播进度更新
|
|
|
*/
|
|
*/
|