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
相关问题
视频播放是否需要创建长时任务
1606浏览 • 1回复 待解决
HarmonyOS 列表视频滚动播放
159浏览 • 1回复 待解决
HarmonyOS AvPlayer视频播放速度问题
289浏览 • 1回复 待解决
AVPlayer实现视频播放
718浏览 • 1回复 待解决
avplayer播放视频demo
1240浏览 • 1回复 待解决
HarmonyOS webview如何播放本地沙箱视频
1231浏览 • 1回复 待解决
HarmonyOS 列表视频全屏播放实现
259浏览 • 1回复 待解决
视频和直播播放HarmonyOS最佳实践
474浏览 • 1回复 待解决
SDK问题,视频播放替代?
110浏览 • 1回复 待解决