Просмотр исходного кода

删除LocalMusic里关于ijkplayer的调用

chendeben 1 год назад
Родитель
Сommit
e52960eb56

+ 13 - 0
entry/src/main/ets/common/service/UnifiedPlayerService.ets

@@ -33,6 +33,7 @@ export interface IPlayerService {
   getCurrentSong(): VideoItem | null;
   getPlaylist(): VideoItem[];
   getCurrentIndex(): number;
+  getCurrentPosition(): number;
   
   // 数据恢复状态
   isDataRestorationCompleted(): boolean;
@@ -856,6 +857,18 @@ async initialize(context: common.UIAbilityContext): Promise<void> {
       LogUtils.getInstance().LOGI(`UnifiedPlayerService updateProgress error: ${error}`);
     }
   }
+  getCurrentPosition(): number {
+    try {
+      const ijkPlayer = this.playerManager.getIjkPlayer();
+      if (!ijkPlayer) {
+        return 0;
+      }
+      return ijkPlayer.getCurrentPosition();
+    } catch (error) {
+      LogUtils.getInstance().LOGI(`UnifiedPlayerService getCurrentPosition error: ${error}`);
+      return 0;
+    }
+  }
 
   private savePlaybackPosition(): void {
     try {

+ 82 - 454
entry/src/main/ets/view/LocalMusic.ets

@@ -49,18 +49,9 @@ import {
 } from '../common/widget/WidgetEventConstants';
 import {
 // DeviceChangeReason,
-  IjkMediaPlayer,
   InterruptEvent,
   InterruptHintType,
-  LogUtils,
-  OnBufferingUpdateListener,
-  OnCompletionListener,
-  OnErrorListener,
-  OnInfoListener,
-  OnPreparedListener,
-  OnSeekCompleteListener,
-  OnTimedTextListener,
-  OnVideoSizeChangedListener
+  LogUtils
 } from '@ohos/ijkplayer';
 import { PlayStatus } from '../common/PlayStatus';
 import fs from '@ohos.file.fs';
@@ -733,7 +724,8 @@ export struct LocalMusic {
       }
 
     }
-    this.mIjkMediaPlayer.on('audioInterrupt', event);
+    // 音频中断处理现在由UnifiedPlayerService统一管理
+    // this.mIjkMediaPlayer.on('audioInterrupt', event); // 已移除,使用UnifiedPlayerService
     // 音频设备断连回调处理
     // let deviceChangeEvent: Callback<InterruptEvent> = (event) => {
     //   LogUtils.getInstance().LOGI(`Heanup deviceChange event: ${JSON.stringify(event)}`);
@@ -1129,11 +1121,13 @@ export struct LocalMusic {
     emitter.off(888);
     emitter.off(333);
     this.mDestroyPage = true;
-    this.mIjkMediaPlayer.setScreenOnWhilePlaying(false);
+    // UnifiedPlayerService会自动管理屏幕常亮状态
+    // this.mIjkMediaPlayer.setScreenOnWhilePlaying(false); // 已移除,使用UnifiedPlayerService
     if (this.CONTROL_PlayStatus != PlayStatus.INIT) {
       this.stop();
     }
-    this.mIjkMediaPlayer.off('audioInterrupt');
+    // 音频中断处理现在由UnifiedPlayerService统一管理
+    // this.mIjkMediaPlayer.off('audioInterrupt'); // 已移除,使用UnifiedPlayerService
     if (workerInstance) {
       workerInstance.terminate();
     }
@@ -6177,7 +6171,7 @@ export struct LocalMusic {
   @Builder
   MusicPlayBuilder() {
     Column() {
-      this.IjkMusicPlayerView()
+      this.MusicPlayerView()
     }
     .height('100%')
     .width('100%')
@@ -6415,7 +6409,7 @@ export struct LocalMusic {
   }
 
   @Builder
-  IjkMusicPlayerView() {
+  MusicPlayerView() {
 
     Column() {
 
@@ -6578,7 +6572,8 @@ export struct LocalMusic {
   private videoUrl: string = '';
   private last: number = 0;
   @State videoParentAspectRatio: number = this.initAspectRatio;
-  private mIjkMediaPlayer = IjkMediaPlayer.getInstance();
+  // 使用UnifiedPlayerService替代ijkMediaPlayer
+  // private mIjkMediaPlayer = IjkMediaPlayer.getInstance(); // 已移除,使用UnifiedPlayerService
   private unifiedPlayerService: IPlayerService = UnifiedPlayerService.getInstance();
   @State CONTROL_PlayStatus: number = PlayStatus.INIT;
   @State PROGRESS_MAX_VALUE: number = 100;
@@ -7522,7 +7517,9 @@ export struct LocalMusic {
           this.mDestroyPage = false;
           this.showLoadIng();
           LogUtils.getInstance().LOGI("slider-->seekValue start:" + value);
-          let seekValue = value * (this.mIjkMediaPlayer.getDuration() / 100);
+          // 通过UnifiedPlayerService获取时长并计算拖动位置
+          const currentState = this.unifiedPlayerService.getCurrentState();
+          let seekValue = value * (currentState.duration / 100);
           this.seekTo(seekValue + "");
           // this.setProgress()
           LogUtils.getInstance().LOGI("slider-->seekValue end:" + seekValue);
@@ -9757,12 +9754,7 @@ export struct LocalMusic {
       LogUtils.getInstance().LOGI(`LocalMusic: Volume set to ${volume} via UnifiedPlayerService`);
     } catch (error) {
       LogUtils.getInstance().LOGI(`LocalMusic setVolume error: ${error}`);
-      // 回退到原有逻辑
-      if (this.mIjkMediaPlayer) {
-        this.mIjkMediaPlayer.setVolume(volume.toString(), volume.toString());
-        this.volume = volume;
-        PreferencesUtil.putSync('DefalutVolume', volume);
-      }
+      ToastUtil.showToast(`设置音量失败: ${error}`);
     }
   }
 
@@ -9774,11 +9766,7 @@ export struct LocalMusic {
       LogUtils.getInstance().LOGI(`LocalMusic: Playback speed set to ${speed} via UnifiedPlayerService`);
     } catch (error) {
       LogUtils.getInstance().LOGI(`LocalMusic setPlaybackSpeed error: ${error}`);
-      // 回退到原有逻辑
-      if (this.mIjkMediaPlayer) {
-        this.mIjkMediaPlayer.setSpeed(speed + 'f');
-        this.playSpeed = speed;
-      }
+      ToastUtil.showToast(`设置播放速度失败: ${error}`);
     }
   }
 
@@ -9995,12 +9983,6 @@ export struct LocalMusic {
       let position = currentState.currentPosition;
       let duration = currentState.duration;
       
-      // 如果UnifiedPlayerService没有有效数据,回退到ijkMediaPlayer
-      if (duration <= 0 && this.mIjkMediaPlayer) {
-        position = this.mIjkMediaPlayer.getCurrentPosition();
-        duration = this.mIjkMediaPlayer.getDuration();
-      }
-      
       let pos = 0;
       if (duration > 0) {
         this.slideEnable = true;
@@ -10029,7 +10011,7 @@ export struct LocalMusic {
       this.isCurrentTime = false
 
       // 检查播放状态以更新随机颜色和跳过逻辑
-      const isPlaying = currentState.isPlaying || (this.mIjkMediaPlayer && this.mIjkMediaPlayer.isPlaying());
+      const isPlaying = currentState.isPlaying;
       if (isPlaying) {
         this.randomColor =
           `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`
@@ -10048,14 +10030,6 @@ export struct LocalMusic {
       this.broadcastProgressIfNeeded();
     } catch (error) {
       LogUtils.getInstance().LOGI(`LocalMusic setProgress error: ${error}`);
-      
-      // 错误处理:回退到原有逻辑
-      if (this.mIjkMediaPlayer) {
-        let position = this.mIjkMediaPlayer.getCurrentPosition();
-        let duration = this.mIjkMediaPlayer.getDuration();
-        this.totalTime = this.stringForTime(duration);
-        this.currentTime = this.stringForTime(position);
-      }
     }
   }
 
@@ -10089,339 +10063,13 @@ export struct LocalMusic {
     this.replayVisible = Visibility.Visible;
   }
 
-  private async play(url: string) {
-    let that = this;
-    that.showLoadIng();
-    //设置XComponent回调的context
-    if (!!this.mContext) {
-      this.mIjkMediaPlayer.setContext(this.mContext, 'xcomponentId');
-    }
-    if (this.CONTROL_PlayStatus == PlayStatus.INIT) {
-      this.mIjkMediaPlayer.reset();
-    }
-    this.CONTROL_PlayStatus = PlayStatus.PLAY;
-    //设置debug模式
-    this.mIjkMediaPlayer.setDebug(false);
-    //初始化配置
-    this.mIjkMediaPlayer.native_setup();
-    // 初始化配置后需要重新设置音频流音量,否则音量为默认值1.0 针对dsf格式设置最大值1.0
-    if(this.videoUrl.toLowerCase().endsWith('.dsf')){
-      this.setVolumeViaService(1.0);
-    }else{
-      this.setVolumeViaService(this.volume);
-    }
-    //设置视频源
-    this.mIjkMediaPlayer.setDataSource(url);
-    //设置视频源http请求头
-    let headers = new Map([
-      ["user_agent", "Mozilla/5.0 BiliDroid/7.30.0 (bbcallen@gmail.com)"],
-      ["referer", "https://www.bilibili.com"]
-    ]);
-    this.mIjkMediaPlayer.setDataSourceHeader(headers);
-    // if(PreferencesUtil.getBooleanSync(SettingPage.IS_MIDIACODEC_OPEN,false)){
-    //   this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", "1"); // 启用硬件解码,会导致无法顺序播放
-    // }
-
-    this.isMusicBGCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
-    //使用精确寻帧 例如,拖动播放后,会寻找最近的关键帧进行播放,很有可能关键帧的位置不是拖动后的位置,而是较前的位置.可以设置这个参数来解决问题
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", "1");
-
-    const fileSize = await this.getFileSize(this.videoUrl);
-    let bufferSize = 1 * 1024 * 1024; // 默认缓冲区大小为2MB
-    if (fileSize > 3 * 1024 * 1024 * 1024) { // 文件大于3GB
-      bufferSize = 25 * 1024 * 1024; // 设置缓冲区大小为25MB
-    }
-
-    //预读数据的缓冲区大小.修复大文件播放前几秒挂掉的bug,太大了会导致倍数播放失效
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-buffer-size", bufferSize + '');
-    //停止预读的最小帧数
-    // this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100");
-
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "reconnect", '1'); ////重连模式,如果中途服务器断开了连接,让它重新连接
-    // 设置其他缓冲相关选项
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "min-frames", "100"); // 设置最小缓冲帧数
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-frames", "1000"); // 设置最大缓冲
-    //启动预加载
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", "1");
-    // 设置无缓冲,这是播放器的缓冲区,有数据就播放
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", "0");
-    //跳帧处理,放CPU处理较慢时,进行跳帧处理,保证播放流程,画面和声音同步
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", "5");
-    // 最大缓冲cache是3s, 有时候网络波动,会突然在短时间内收到好几秒的数据
-    // 因此需要播放器丢包,才不会累积延时
-    // 这个和第三个参数packet-buffering无关。
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max_cached_duration", "3000");
-    // 无限制收流
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1");
-    this.mIjkMediaPlayer.setOptionLong(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "infbuf", "1")
-    // 屏幕常亮
-    this.mIjkMediaPlayer.setScreenOnWhilePlaying(true);
-    // 设置超时
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", "10000000");
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "connect_timeout", "10000000");
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "addrinfo_timeout", "10000000");
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "dns_cache_timeout", "10000000");
-    // 变速播放
-    this.mIjkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "soundtouch", "1");
-    this.setPlaybackSpeedViaService(this.playSpeed);
-    let Speed = this.mIjkMediaPlayer.getSpeed()
-    LogUtils.getInstance().LOGI('getSpeed--' + Speed)
-    //是否开启循环播放
-    // this.mIjkMediaPlayer.setLoopCount(this.loop);
-    let mOnVideoSizeChangedListener: OnVideoSizeChangedListener = {
-      onVideoSizeChanged: (width: number, height: number, sar_num: number, sar_den: number) => {
-        if (height === 0) {
-          return;
-        }
-        const va = width / height;
-        const vpa = that.videoParentAspectRatio;
-        if (vpa > va) {
-          that.videoWidth = (width / (height * vpa)) * 100 + '%';
-        } else {
-          that.videoWidth = '100%';
-        }
-        if (width && height) {
-          that.videoAspectRatio = width / height;
-        }
-        LogUtils.getInstance()
-          .LOGI("setOnVideoSizeChangedListener-->go:" + width + "," + height + "," + sar_num + "," + sar_den);
-
-        that.hideLoadIng();
-      }
-    }
-    this.mIjkMediaPlayer.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener);
-    let mOnPreparedListener: OnPreparedListener = {
-      onPrepared: async () => {
-        LogUtils.getInstance().LOGI("setOnPreparedListener-->go");
-        try {
-          // this.cover = this.songList[this.curIndex].pixelMapPath
-          // this.artist = this.songList[this.curIndex].artist
-          // this.videoUrl = this.songList[this.curIndex].filePath
-
-          let isBgCover = PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_BG_COVER, true)
-          if (isBgCover && this.cover !== undefined && StrUtil.isNotEmpty(this.cover)) {
-            this.setImageColor2(this.cover)
-          } else {
-            this.getImageColor();
-          }
-          //保存碰一碰分享的当前的歌曲
-          AppStorage.setOrCreate('currentSong',this.currentSong) ;
-
-          let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
-
-          await this.initLyric(lyricPath);
-
-
-          setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
-            this.avSessionController.initAvSession(false);
-            this.avSessionController.setAVMetadataMusic(this.songList[this.curIndex], this.duration, this.lyricContent);
-
-            this.setAvSessionListener();
-
-            this.updateSessionPlayState(true)
-            this.setCurrentPlayMode()
-          }, 500)
-
-
-          let timeoutPlay = 0
-          if (StrUtil.isNotEmpty(this.videoUrl) &&
-            (this.videoUrl.toLowerCase().endsWith('.rmvb') || this.videoUrl.toLowerCase().endsWith('.flac'))) {
-            timeoutPlay = 1000
-          }
-
-          //跳过片头片尾关键代码,以下是跳过片头的关键代码
-          if (this.modeType === 0) { //文件夹
-            let parentPath = FileUtil.getParentPath(this.videoUrl)
-            this.jumpTopTime = PreferencesUtil.getNumberSync(parentPath + 'jumpTopTime')
-            this.jumpEndTime = PreferencesUtil.getNumberSync(parentPath + 'jumpEndTime')
-            this.isOpenJump = PreferencesUtil.getBooleanSync(parentPath + 'isOpenJump', false)
-          } else if (this.modeType === 1) { //媒体库
-            this.jumpTopTime = PreferencesUtil.getNumberSync(1 + 'jumpTopTime')
-            this.jumpEndTime = PreferencesUtil.getNumberSync(1 + 'jumpEndTime')
-            this.isOpenJump = PreferencesUtil.getBooleanSync(1 + 'isOpenJump', false)
-          } else if (this.modeType === 2) { //艺术家
-            if (this.currentSong?.artist) {
-              this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpTopTime')
-              this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.artist + 2 + 'jumpEndTime')
-              this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.artist + 2 + 'isOpenJump', false)
-            }
-
-          } else if (this.modeType === 3) { //专辑
-            if (this.currentSong?.album) {
-              this.jumpTopTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpTopTime')
-              this.jumpEndTime = PreferencesUtil.getNumberSync(this.currentSong?.album + 3 + 'jumpEndTime')
-              this.isOpenJump = PreferencesUtil.getBooleanSync(this.currentSong?.album + 3 + 'isOpenJump', false)
-            }
-
-          }
-          this.duration = this.mIjkMediaPlayer.getDuration()
-          if (this.isOpenJump) { //用户是否设置跳过片头片尾
-            if (this.mIjkMediaPlayer != null) {
-              if (this.jumpTopTime * 1000 <= this.duration) {
-                // 调用 seekTo 方法,跳到指定时间
-
-                setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
-                  if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
-                    this.seekTo(this.jumpTopTime * 1000 + ""); // 跳到开头
-                  }
-
-                }, timeoutPlay)
-
-              } else {
-                // 提示用户无法跳过
-                ToastUtil.showToast('跳过时间超过视频时长');
-              }
-
-            }
-          } else {
-            this.jumpTopTime = 0
-            this.jumpEndTime = 0
-            console.error('onecold 最后一首: isFirstStartPlay = ' + this.isFirstStartPlay);
-            console.error('onecold 最后一首: isMemoryLastPlay = ' + this.isMemoryLastPlay);
-            console.error('onecold 最后一首: PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false) = ' +
-            PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false));
-
-            //记忆播放(每一首都会记忆播放)
-            if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
-              setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
-                if (PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false)) {
-                  this.restorePlaybackPosition() //读取播放记忆功能
-                } else if (this.isMemoryLastPlay && this.isFirstStartPlay) {
-                  console.error('onecold 最后一首:读取播放记忆功能  = ' + this.isFirstStartPlay);
-                  this.restorePlaybackPosition() //读取播放记忆功能
-                }
-                this.isFirstStartPlay = false
-
-              }, timeoutPlay)
-
-            } else {
-              this.isFirstStartPlay = false
-            }
-
-          }
-
-
-          this.saveLastPlayList()
-
-        } catch (error) {
-          let err: BusinessError = error as BusinessError;
-          console.error('onecold failed with err: ' + JSON.stringify(err));
-        }
-
-
-      }
-    }
-    this.mIjkMediaPlayer.setOnPreparedListener(mOnPreparedListener);
-
-    let mOnTimedTextListener: OnTimedTextListener = {
-      onTimedText: () => {
-      }
-    }
-    this.mIjkMediaPlayer.setOnTimedTextListener(mOnTimedTextListener)
-
-    let mOnCompletionListener: OnCompletionListener = {
-      onCompletion: () => {
-
-        LogUtils.getInstance().LOGI("OnCompletionListener-->go")
-        if (this.playType == 0) { //0:连续播放  1:单片重复播放 2:正常播放
-          this.playNext()
-        } else if (this.playType == 1) { //1:单片重复播放
-          this.CONTROL_PlayStatus = PlayStatus.INIT
-          that.startPlayOrResumePlay();
-
-        } else if (this.playType == 2) { //2:正常播放,单曲播完
-
-          that.showRePlay();
-          that.currentTime = that.stringForTime(this.mIjkMediaPlayer.getDuration());
-          that.progressValue = this.PROGRESS_MAX_VALUE;
-          that.slideEnable = false;
-          that.stop();
-          // ToastUtil.showToast('开始重新播放')
-        } else if (this.playType == 3) { //3:随机播放
-          this.randomPlay()
-
-        }
-
-
-      }
-    }
-    this.mIjkMediaPlayer.setOnCompletionListener(mOnCompletionListener);
-
-    let mOnBufferingUpdateListener: OnBufferingUpdateListener = {
-      onBufferingUpdate: (percent: number) => {
-
-        LogUtils.getInstance().LOGI("OnBufferingUpdateListener-->go:" + percent);
-        let MediaInfo = this.mIjkMediaPlayer.getMediaInfo()
-        LogUtils.getInstance().LOGI('getMediaInfo---' + MediaInfo);
-        let VideoWidth = this.mIjkMediaPlayer.getVideoWidth()
-        LogUtils.getInstance().LOGI('getVideoWidth---' + VideoWidth);
+  // 原来的 play 方法已移除,播放逻辑现在由 UnifiedPlayerService 统一处理
+  // private async play(url: string) { ... } 已移除
 
-        let VideoHeight = this.mIjkMediaPlayer.getVideoHeight()
-        LogUtils.getInstance().LOGI('getVideoHeight---' + VideoHeight);
 
-        let VideoSarNum = this.mIjkMediaPlayer.getVideoSarNum()
-        LogUtils.getInstance().LOGI('getVideoSarNum---' + VideoSarNum);
 
-        let VideoSarDen = this.mIjkMediaPlayer.getVideoSarDen()
-        LogUtils.getInstance().LOGI('getVideoSarDen---' + VideoSarDen);
 
-        let AudioSessionId = this.mIjkMediaPlayer.getAudioSessionId()
-        LogUtils.getInstance().LOGI('getAudioSessionId---' + AudioSessionId);
-
-        let Looping = this.mIjkMediaPlayer.isLooping()
-        LogUtils.getInstance().LOGI('isLooping---' + Looping);
-      }
-    }
-    this.mIjkMediaPlayer.setOnBufferingUpdateListener(mOnBufferingUpdateListener);
-
-    let mOnSeekCompleteListener: OnSeekCompleteListener = {
-      onSeekComplete: () => {
-        LogUtils.getInstance().LOGI("OnSeekCompleteListener-->go");
-
-        that.startPlayOrResumePlay();
-
-      }
-    }
-    this.mIjkMediaPlayer.setOnSeekCompleteListener(mOnSeekCompleteListener);
-
-    let mOnInfoListener: OnInfoListener = {
-      onInfo: (what: number, extra: number) => {
-        LogUtils.getInstance().LOGI("OnInfoListener-->go:" + what + "===" + extra);
-        that.hideLoadIng();
-      }
-    }
-    this.mIjkMediaPlayer.setOnInfoListener(mOnInfoListener);
-
-
-    let mOnErrorListener: OnErrorListener = {
-      onError: (what: number, extra: number) => {
-        this.stopProgressTask();
-        LogUtils.getInstance().LOGI("OnErrorListener-->go:" + what + "===" + extra + " this.videoUrl=" + this.videoUrl)
-        that.hideLoadIng();
-
-        if (StrUtil.isNotEmpty(this.videoUrl) && !FileUtil.accessSync(this.videoUrl)) {
-          ToastUtil.showToast(Utility.resourceToString(getContext(), $r('app.string.file_not_exist')))
-        } else {
-          ToastUtil.showToast(getContext()
-            .resourceManager
-            .getStringByNameSync("Honey_the_video_is_playing_errant_The_system_is_wandering"))
-
-        }
-
-      }
-    }
-
-
-    this.mIjkMediaPlayer.setOnErrorListener(mOnErrorListener);
-
-    this.mIjkMediaPlayer.setMessageListener();
-
-    this.mIjkMediaPlayer.prepareAsync();
-
-    this.mIjkMediaPlayer.start();
-
-
-  }
+  // 所有的播放器配置和监听器设置已移至 UnifiedPlayerService
 
   //保存最后播放的那首歌和已经对应的播放列表
   saveLastPlayList() {
@@ -10488,13 +10136,12 @@ export struct LocalMusic {
   }
 
   private sessionSetLoopModeCallback = (mode: number) => {
-    if (this.mIjkMediaPlayer != null) {
-      ToastUtil.showToast('当前播放模式:' + mode)
-      Logger.info('onecold 当前播放模式= ' + mode)
-      let hmPlayMode = mode + 1
-      if (hmPlayMode >= 4) {
-        hmPlayMode = 0
-      }
+    ToastUtil.showToast('当前播放模式:' + mode)
+    Logger.info('onecold 当前播放模式= ' + mode)
+    let hmPlayMode = mode + 1
+    if (hmPlayMode >= 4) {
+      hmPlayMode = 0
+    }
       if (hmPlayMode === 1) {
         this.setPlayModeViaService(1);
         ToastUtil.showToast('单曲循环')
@@ -10519,7 +10166,6 @@ export struct LocalMusic {
       });
 
     }
-  }
 
   setCurrentPlayMode() {
     if (!this.avSessionController) {
@@ -10553,7 +10199,7 @@ export struct LocalMusic {
   }
 
   private sessionToggleFavoriteCallback = (assetId: string) => {
-    if (this.mIjkMediaPlayer != null && this.currentSong) {
+    if (this.currentSong) {
       console.info(`on toggleFavorite `);
       // 应用收到收藏命令,进行收藏处理。
 
@@ -10642,13 +10288,27 @@ export struct LocalMusic {
     // if(!this.isBgPlayOpen)
     //   return
     Logger.info(TAG, `updateIsPlay isPlay: ${isPlay}`);
-    this.setAVSessionPlayState({
-      state: isPlay ? avSession.PlaybackState.PLAYBACK_STATE_PLAY : avSession.PlaybackState.PLAYBACK_STATE_PAUSE,
-      position: {
-        elapsedTime: this.mIjkMediaPlayer.getCurrentPosition(),
-        updateTime: new Date().getTime()
-      }
-    });
+    try {
+      // 通过UnifiedPlayerService获取当前位置
+      const currentState = this.unifiedPlayerService.getCurrentState();
+      this.setAVSessionPlayState({
+        state: isPlay ? avSession.PlaybackState.PLAYBACK_STATE_PLAY : avSession.PlaybackState.PLAYBACK_STATE_PAUSE,
+        position: {
+          elapsedTime: currentState.currentPosition,
+          updateTime: new Date().getTime()
+        }
+      });
+    } catch (error) {
+      LogUtils.getInstance().LOGI(`updateSessionPlayState error: ${error}`);
+      // 如果获取失败,使用默认值
+      this.setAVSessionPlayState({
+        state: isPlay ? avSession.PlaybackState.PLAYBACK_STATE_PLAY : avSession.PlaybackState.PLAYBACK_STATE_PAUSE,
+        position: {
+          elapsedTime: 0,
+          updateTime: new Date().getTime()
+        }
+      });
+    }
   }
 
   private setAVSessionPlayState(playbackState: avSession.AVPlaybackState): void {
@@ -10708,7 +10368,7 @@ export struct LocalMusic {
         mediaType: 'VIDEO',
         mediaSize: item.videoSize,
         //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
-        startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
+        startPosition: this.unifiedPlayerService.getCurrentPosition(),
         // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
         duration: this.duration,
         // albumCoverUri: 'https://www.example.jpeg',
@@ -10755,7 +10415,7 @@ export struct LocalMusic {
         mediaType: 'AUDIO',
         mediaSize: item.videoSize,
         //startPosition为投播当前进度,设置该字段可将本机播放进度同步到远端
-        startPosition: this.mIjkMediaPlayer.getCurrentPosition(),
+        startPosition: this.unifiedPlayerService.getCurrentPosition(),
         // 投播资源播放时长,设置该字段可将本机播放时长同步到远端显示
         duration: this.duration,
         // albumCoverUri: 'https://www.example.jpeg',
@@ -10815,21 +10475,25 @@ export struct LocalMusic {
     if (!time) {
       return;
     }
-    if (this.mIjkMediaPlayer != null) {
-      const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
+    try {
+      // 通过UnifiedPlayerService获取当前位置
+      const currentState = this.unifiedPlayerService.getCurrentState();
+      const curPosition = currentState.currentPosition;
       let seeTime = curPosition + time * 1000;
+      
       // 限制 seekValue 在合法范围内
       if (seeTime < 0) {
         seeTime = 0;
-      } else if (seeTime > this.duration) {
-        seeTime = this.duration;
+      } else if (seeTime > currentState.duration) {
+        seeTime = currentState.duration;
       }
+      
       Logger.info('onecold seeTime= ' + seeTime)
       this.setSeekToActionProgress(seeTime)
       this.seekTo(seeTime + "")
+    } catch (error) {
+      LogUtils.getInstance().LOGI(`sessionFastForwardCallback error: ${error}`);
     }
-
-
   };
 
   /**
@@ -10839,7 +10503,7 @@ export struct LocalMusic {
    */
   private setSeekToActionProgress(position: number) {
     // let position = this.mIjkMediaPlayer.getCurrentPosition();
-    let duration = this.mIjkMediaPlayer.getDuration();
+    let duration: number = this.unifiedPlayerService.getCurrentPosition();
     let pos = 0;
     if (duration > 0) {
       this.slideEnable = true;
@@ -10866,25 +10530,21 @@ export struct LocalMusic {
     if (!time) {
       return;
     }
-    if (this.mIjkMediaPlayer != null) {
-      const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
-      let seeTime = curPosition - time * 1000;
-      // 限制 seekValue 在合法范围内
-      if (seeTime < 0) {
-        seeTime = 0;
-      } else if (seeTime > this.duration) {
+    const curPosition: number = this.unifiedPlayerService.getCurrentPosition()
+    let seeTime = curPosition - time * 1000;
+    // 限制 seekValue 在合法范围内
+    if (seeTime < 0) {
+      seeTime = 0;
+    } else if (seeTime > this.duration) {
         seeTime = this.duration;
       }
       Logger.info('onecold seeTime= ' + seeTime)
       this.setSeekToActionProgress(seeTime)
       this.seekTo(seeTime + "")
-    }
   };
   private sessionSeekCallback = (seekTime: number) => {
-    if (this.mIjkMediaPlayer != null) {
-      const curPosition = this.mIjkMediaPlayer.getCurrentPosition()
-      this.seekTo(seekTime + "")
-    }
+    const curPosition: number = this.unifiedPlayerService.getCurrentPosition()
+    this.seekTo(seekTime + "")
   };
 
   private async getFileSize(filePath: string): Promise<number> {
@@ -10922,18 +10582,6 @@ export struct LocalMusic {
     } catch (error) {
       LogUtils.getInstance().LOGI(`LocalMusic pause error: ${error}`);
       ToastUtil.showToast(`暂停失败: ${error}`);
-      
-      // 错误处理:回退到原有逻辑
-      if (this.mIjkMediaPlayer && this.mIjkMediaPlayer.isPlaying()) {
-        this.savePlaybackPosition();
-        this.mIjkMediaPlayer.pause();
-        this.setProgress();
-        this.mDestroyPage = true;
-        this.CONTROL_PlayStatus = PlayStatus.PAUSE;
-        this.setIsPlaying(false);
-        this.updateSessionPlayState(false)
-        this.playChange()
-      }
     }
   }
 
@@ -10957,28 +10605,16 @@ export struct LocalMusic {
     } catch (error) {
       LogUtils.getInstance().LOGI(`LocalMusic stop error: ${error}`);
       ToastUtil.showToast(`停止播放失败: ${error}`);
-      
-      // 错误处理:回退到原有逻辑
-      this.savePlaybackPosition();
-      this.CONTROL_PlayStatus = PlayStatus.INIT;
-      this.setIsPlaying(false);
-      if (this.mIjkMediaPlayer) {
-        this.mIjkMediaPlayer.stop();
-        this.mIjkMediaPlayer.release();
-      }
-      this.stopProgressTask();
-      this.updateSessionPlayState(false)
-      this.playChange()
-      this.watchStatus();
     }
   }
 
   //保持记忆播放功能
   private savePlaybackPosition() {
-    if (this.mIjkMediaPlayer != null) {
-      const position = this.mIjkMediaPlayer.getCurrentPosition();
-      // ToastUtil.showToast('保存记忆播放 = ' + position)
-      const duration = this.mIjkMediaPlayer.getDuration();
+    try {
+      // 通过UnifiedPlayerService获取当前播放位置
+      const currentState = this.unifiedPlayerService.getCurrentState();
+      const position = currentState.currentPosition;
+      const duration = currentState.duration;
       const threshold = 5000; // 阈值,单位为毫秒(这里设为5秒)
 
       // 如果播放位置接近视频末尾,则保存 position 为 0
@@ -10989,6 +10625,8 @@ export struct LocalMusic {
       AppStorage.setOrCreate(`playback_${this.videoUrl}`, playbackPosition);
 
       LogUtils.getInstance().LOGI(`Saved playback position: ${playbackPosition}ms for ${this.name}`);
+    } catch (error) {
+      LogUtils.getInstance().LOGI(`savePlaybackPosition error: ${error}`);
     }
   }
 
@@ -11001,7 +10639,7 @@ export struct LocalMusic {
     }
     
     // ToastUtil.showToast('position = ' + position)
-    if (this.mIjkMediaPlayer != null && position > 0) {
+    if (position > 0) {
       // ToastUtil.showToast('seekTo = ' + position)
       this.seekTo(position + "");
       LogUtils.getInstance().LOGI(`Restored playback position: ${position}ms for ${this.name}`);
@@ -11027,16 +10665,6 @@ export struct LocalMusic {
       } else {
         ToastUtil.showToast(`拖动失败: ${error}`);
       }
-      
-      // 错误处理:回退到原有逻辑
-      if (StrUtil.isNotEmpty(this.videoUrl) && this.videoUrl.toLowerCase().endsWith('.wma')) {
-        ToastUtil.showToast('wma格式不支持拖动快进。')
-        return
-      }
-      if (this.mIjkMediaPlayer) {
-        this.mIjkMediaPlayer.seekTo(value);
-        this.setProgress()
-      }
     }
   }
 
@@ -12012,7 +11640,7 @@ export struct LocalMusic {
    */
   private handleWidgetSeekTo(percentage: number): void {
     try {
-      if (this.mIjkMediaPlayer && this.duration > 0) {
+      if (this.duration > 0) {
         const targetPosition = (percentage / 100) * this.duration;
         this.seekTo(targetPosition.toString());
         LogUtils.getInstance().LOGI(`Widget seek to: ${percentage}% (${targetPosition}ms)`);
@@ -12058,7 +11686,7 @@ export struct LocalMusic {
    */
   private broadcastPlayerProgress(): void {
     try {
-      const currentPos = this.mIjkMediaPlayer?.getCurrentPosition() || 0;
+      const currentPos: number = this.unifiedPlayerService.getCurrentPosition() || 0;
       const progressData: PlayProgress = {
         currentPosition: currentPos,
         duration: this.duration || 0,
@@ -12125,10 +11753,10 @@ export struct LocalMusic {
       };
 
       const progress: PlayProgress = {
-        currentPosition: this.mIjkMediaPlayer?.getCurrentPosition() || 0,
+        currentPosition: this.unifiedPlayerService.getCurrentPosition() || 0,
         duration: this.duration || 0,
-        percentage: this.duration > 0 ? ((this.mIjkMediaPlayer?.getCurrentPosition() || 0) / this.duration) * 100 : 0,
-        currentTimeText: this.stringForTime(this.mIjkMediaPlayer?.getCurrentPosition() || 0),
+        percentage: this.duration > 0 ? ((this.unifiedPlayerService.getCurrentPosition() || 0) / this.duration) * 100 : 0,
+        currentTimeText: this.stringForTime(this.unifiedPlayerService.getCurrentPosition() || 0),
         totalTimeText: this.stringForTime(this.duration || 0)
       };