HarmonyOS 视频播放结束后,重播,需要点击重播点两遍才能重播

视频播放结束后,需要点击两遍重播,才能重头开始播放。

在播放器播放完成后,COMPLETED状态会调用this.avPlayer.stop(),点击重播,调用this.avPlayer?.prepare(),但是点一遍,日志输出AVPlayer state stopped called,点第二遍,状态才变成prepared,日志输出AVPlayer state prepared called。

尝试在点击重播时直接在代码里调用两次this.avPlayer?.prepare()也不行,必须有间隔时间调用两次this.avPlayer?.prepare()才能重播。请问不能直接调用一次this.avPlayer?.prepare()来实现重播吗,还需要调用什么?以下是状态流转时的操作:

this.avPlayer.on(PlayerEvent.STATE_CHANGE, async (state: string, reason: media.StateChangeReason) => { 
  switch (state) { 
    case PlayerState.IDLE: 
      console.info('AVPlayer state idle called.') 
      this.avPlayer.release() 
      break 
    case PlayerState.INITIALIZED: 
      console.info('xxx','AVPlayer state initialized called.') 
      this.avPlayer.surfaceId = this.surfaceId // 设置显示画面,当播放的资源为纯音频时无需设置 
      this.avPlayer.prepare() 
      break 
    case PlayerState.PREPARED: 
      console.info('xxx', 'AVPlayer state prepared called.') 
      this.avPlayer.play() 
      break 
    case PlayerState.PLAYING: 
      console.info('xxx', 'AVPlayer state playing called.') 
      break 
    case PlayerState.PAUSED: 
      console.info('xxx','AVPlayer state paused called.') 
      break 
    case PlayerState.COMPLETED: 
      console.info('xxx','AVPlayer state completed called.') 
      this.context.eventHub.emit(VideoEvent.PLAY_COMPLETE) 
      this.avPlayer.stop() 
      break 
    case PlayerState.STOPPED: 
      console.info('xxx','AVPlayer state stopped called.') 
      break 
    case PlayerState.RELEASED: 
      console.info('xxx','AVPlayer state released called.') 
      break 
    default: 
      console.info('xxx','AVPlayer state unknown called.') 
      break 
  } 
})
HarmonyOS
2024-08-14 16:47:55
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Heiang

代码如下:


分享
微博
QQ
微信
回复
2024-08-14 20:52:52
相关问题
HarmonyOS 需要视频小窗播放功能
26浏览 • 1回复 待解决
视频播放是否需要创建长时任务
1912浏览 • 1回复 待解决
HarmonyOS 视频播放相关
70浏览 • 1回复 待解决
HarmonyOS 个List互相锚功能
27浏览 • 1回复 待解决
HarmonyOS XComponent播放视频问题
32浏览 • 1回复 待解决
HarmonyOS 视频后台播放问题
25浏览 • 1回复 待解决
HarmonyOS 列表视频滚动播放
422浏览 • 1回复 待解决
HarmonyOS 视频列表播放问题
75浏览 • 1回复 待解决