#鸿蒙通关秘籍#在鸿蒙视频播放器中如何实现切换播放进度的功能?

HarmonyOS
2024-12-02 13:39:50
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
云端诗人SEO

为了让视频播放器能够跳转到指定播放位置,需在播放器类中定义 seekTime() 方法。这一方法通过调用 AVPlayerseek() 实现。调用此方法时,将播放进度设置为指定位置,并检查播放器状态,如果处于暂停状态则开启播放。可以参考以下代码实现:

import media from '@ohos.multimedia.media'

export class VideoAVPlayerClass {
  static player: media.AVPlayer | null = null
  static duration: number = 0
  static time: number = 0
  static isPlay: boolean = false
  static playList: videoItemType[] = []
  static playIndex: number = 0
  static surfaceId: string = ''

  static seekTime(time: number) {
    VideoAVPlayerClass.time = time
    VideoAVPlayerClass.avPlayer.seek(VideoAVPlayerClass.time)

    if (!VideoAVPlayerClass.isPlay) {
      VideoAVPlayerClass.isPlay = true
      VideoAVPlayerClass.avPlayer.play()
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
分享
微博
QQ
微信
回复
2024-12-02 15:52:04


相关问题
使用AVPlayer实现视频播放器
2369浏览 • 1回复 待解决
HarmonyOS 视频播放器问题
1066浏览 • 1回复 待解决
HarmonyOS 播放器功能拓展
738浏览 • 1回复 待解决