HarmonyOS video组件 设置自定义控制器时,全屏不显示控制器

video 组件需要自定义控制器 全屏时 保持横屏。

HarmonyOS
2024-09-24 12:37:30
766浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

video自带的全屏不能自定义设置控件

可以给视频展示区一个高度,通过调整尺寸实现全屏的效果,同时也可以显示自定义的播放控件

参考以下demo:

// xxx.ets  
import { window } from '@kit.ArkUI'  
  
@Entry  
@Component  
struct VideoCreateComponent {  
  @State videoSrc: Resource = $rawfile('demo.mp4')  
  @State previewUri: Resource = $r('app.media.startIcon')  
  @State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X  
  @State isAutoPlay: boolean = false  
  @State showControls: boolean = true  
  @State videoHeight: string = '600vp'  
  controller: VideoController = new VideoController()  
  @State windowClass:window.Window|undefined = undefined  
  aboutToAppear(): void {  
    window.getLastWindow(getContext(this)).then((window)=>{  
      this.windowClass = window  
    })  
  }  
  
  build() {  
    Stack() {  
      Video({  
        src: this.videoSrc,  
        previewUri: this.previewUri,  
        currentProgressRate: this.curRate,  
        controller: this.controller  
      })  
        .width('100%')  
        .height(this.videoHeight)  
        .autoPlay(this.isAutoPlay)  
        .controls(this.showControls)  
  
      Row() {  
        Button('controls').onClick(() => {  
          this.showControls = !this.showControls // 切换是否显示视频控制栏  
        }).margin(5)  
        Button('start').onClick(() => {  
          this.controller.start() // 开始播放  
        }).margin(5)  
        Button('pause').onClick(() => {  
          this.controller.pause() // 暂停播放  
        }).margin(5)  
        Button('fullscreen').onClick(async () => {  
          if(!this.windowClass){  
            return;  
          }  
          if(this.videoHeight === '100%'){  
            this.windowClass.setWindowLayoutFullScreen(false).then(()=>{  
              this.videoHeight = '600vp'  
            })  
          }else{  
            this.windowClass.setWindowLayoutFullScreen(true).then(()=>{  
              this.videoHeight = '100%'  
            })  
          }  
        }).margin(5)  
      }  
    }  
    .alignContent(Alignment.Bottom)  
  }  
}  
  
interface DurationObject {  
  duration: number;  
}  
  
interface TimeObject {  
  time: number;  
}
  • 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.
分享
微博
QQ
微信
回复
2024-09-24 15:25:26


相关问题
HarmonyOS video空间自定义控制器
1116浏览 • 1回复 待解决
HarmonyOS 自定义视频控制器
894浏览 • 1回复 待解决
HarmonyOS 自定义对话框的控制器
583浏览 • 1回复 待解决
什么是控制器controller
1993浏览 • 1回复 待解决
HarmonyOS List控制器Scroller相关
911浏览 • 1回复 待解决
如何自定义Video组件控制栏样式
3630浏览 • 1回复 待解决
模拟Hilog打印日志,控制不显示
14212浏览 • 4回复 待解决