HarmonyOS 视频播放无缝切换

视频播放由竖屏,切换为横屏全屏,想要无缝切换。A页面有一个列表,列表中有一个视频组件,当点击全屏播放时,携带当前播放索引,播放url等参数,跳转B页面同时旋转屏幕,在新的B页面创建了新的Video组件,然后seek到指定索引,并播放。但是这种切换形式不够。

HarmonyOS
2024-12-25 15:32:49
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

可以参考如下demo:

import { window } from '@kit.ArkUI';

@Entry
@Component
struct ListExample {
  controller0: VideoController = new VideoController();
  controller1: VideoController = new VideoController();
  @State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X
  @State fullHeight: Length = 300
  @State isFullVertical: boolean = false
  @State isFullHorizontal: boolean = false
  onPageHide(): void {
    this.handlerOrientation(window.Orientation.PORTRAIT)
  }

  handlerOrientation(type: number) {
    window.getLastWindow(getContext(this), (err, win) => {
      win.setPreferredOrientation(type)
    })
  }

  build() {
    Column() {
      List({ space: 20, initialIndex: 0 }) {
        // ForEach(this.arr, (item: number,index:number) => {
        ListItem() {
          Stack({ alignContent: Alignment.Bottom }) {
            Video({
              src: $rawfile('videoTest.mp4'),
              previewUri: $r('app.media.app_icon'),
              currentProgressRate: this.curRate,
              controller: this.controller0
            })
              .width('100%')
              .height(this.fullHeight)
              .loop(false)
              .objectFit(ImageFit.Contain)
              .autoPlay(false)
              .controls(false)
              .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
            Row() {
              Text('播放').onClick(() => {
                this.controller0.start() // 开始播放
              }).margin(5).fontColor(Color.White).fontSize(12)
              Text('暂停').onClick(() => {
                this.controller0.pause() // 暂停播放
              }).margin(5).fontColor(Color.White).fontSize(12)
              Text('0.75X').onClick(() => {
                this.curRate = PlaybackSpeed.Speed_Forward_0_75_X
              }).margin(5).fontColor(Color.White).fontSize(12)
              Text('1.0X').onClick(() => {
                this.curRate = PlaybackSpeed.Speed_Forward_1_00_X
              }).margin(5).fontColor(Color.White).fontSize(12)
              Text('2.0').onClick(() => {
                this.curRate = PlaybackSpeed.Speed_Forward_2_00_X
              }).margin(5).fontColor(Color.White).fontSize(12)
              Text(this.isFullVertical ? '退出竖屏' : '竖屏')
                .margin(5)
                .fontSize(12)
                .onClick(() => {
                  if (this.isFullVertical) {
                    this.fullHeight = 600
                  } else {
                    this.fullHeight = '100%'
                  }
                  this.isFullVertical = !this.isFullVertical
                }).fontColor(Color.White)
              Text(this.isFullHorizontal ? '退出横屏' : '横屏')
                .fontSize(12)
                .onClick(() => {
                  this.isFullHorizontal = !this.isFullHorizontal
                  if (this.isFullHorizontal) {
                    this.handlerOrientation(window.Orientation.LANDSCAPE_INVERTED)
                    this.fullHeight = '100%'
                  } else {
                    this.handlerOrientation(window.Orientation.PORTRAIT)
                    this.fullHeight = 600
                  }
                }).fontColor(Color.White)
            }
            .zIndex(1)
          }
        }

        ListItem() {
          Stack({ alignContent: Alignment.Bottom }) {
            Video({
              src: $rawfile('videoTest.mp4'),
              previewUri: $r('app.media.app_icon'),
              currentProgressRate: this.curRate,
              controller: this.controller1
            })
              .width('100%')
              .height(this.fullHeight)
              .loop(false)
              .objectFit(ImageFit.Contain)
              .autoPlay(false)
              .controls(false)
              .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
            Row() {
              Text('播放').onClick(() => {
                this.controller1.start() // 开始播放
              }).margin(5).fontColor(Color.White).fontSize(12)
              Text('暂停').onClick(() => {
                this.controller1.pause() // 暂停播放
              }).margin(5).fontColor(Color.White).fontSize(12)
              Text('0.75X').onClick(() => {
                this.curRate = PlaybackSpeed.Speed_Forward_0_75_X
              }).margin(5).fontColor(Color.White).fontSize(12)
              Text('1.0X').onClick(() => {
                this.curRate = PlaybackSpeed.Speed_Forward_1_00_X
              }).margin(5).fontColor(Color.White).fontSize(12)
              Text('2.0').onClick(() => {
                this.curRate = PlaybackSpeed.Speed_Forward_2_00_X
              }).margin(5).fontColor(Color.White).fontSize(12)
              Text(this.isFullVertical ? '退出竖屏' : '竖屏')
                .margin(5)
                .fontSize(12)
                .onClick(() => {
                  if (this.isFullVertical) {
                    this.fullHeight = 600
                  } else {
                    this.fullHeight = '100%'
                  }
                  this.isFullVertical = !this.isFullVertical
                }).fontColor(Color.White)
              Text(this.isFullHorizontal ? '退出横屏' : '横屏')
                .fontSize(12)
                .onClick(() => {
                  this.isFullHorizontal = !this.isFullHorizontal
                  if (this.isFullHorizontal) {
                    this.handlerOrientation(window.Orientation.LANDSCAPE_INVERTED)
                    this.fullHeight = '100%'
                  } else {
                    this.handlerOrientation(window.Orientation.PORTRAIT)
                    this.fullHeight = 600
                  }
                }).fontColor(Color.White)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
分享
微博
QQ
微信
回复
2024-12-25 18:44:10
相关问题
HarmonyOS 视频播放
857浏览 • 1回复 待解决
HarmonyOS 视频渲染播放
768浏览 • 1回复 待解决
HarmonyOS 视频播放相关
1050浏览 • 1回复 待解决
HarmonyOS 视频后台播放问题
791浏览 • 1回复 待解决
HarmonyOS 视频列表播放问题
681浏览 • 1回复 待解决
HarmonyOS 列表视频滚动播放
1019浏览 • 1回复 待解决
HarmonyOS XComponent播放视频问题
955浏览 • 1回复 待解决
HarmonyOS 后台播放视频问题
608浏览 • 1回复 待解决
HarmonyOS 播放flv文件视频
658浏览 • 1回复 待解决
HarmonyOS 音频播放设备的切换
1234浏览 • 1回复 待解决