HarmonyOS使用Video组件全屏播放时,如何自定义工具栏?

视频列表,在Item中通过controls(false)自定义了工具栏,点击全屏播放按钮后,无法显示,请问如何更改?

HarmonyOS
2024-10-08 11:15:37
1205浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

demo如下:

import { window } from '@kit.ArkUI'  
@Entry  
@Component  
struct VideoCreateComponent {  
  @State videoSrc: Resource = $rawfile('video3.mp4')  
  @State previewUri: Resource = $r('app.media.startIcon')  
  @State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X  
  @State isAutoPlay: boolean = false  
  @State showControls: boolean = false  
  @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)  
  }  
}
  • 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.
分享
微博
QQ
微信
回复
2024-10-08 17:04:20
相关问题
如何自定义Video组件控制样式
3642浏览 • 1回复 待解决
HarmonyOS Web组件如何实现视频全屏播放
1761浏览 • 1回复 待解决
HarmonyOS Web全屏播放适配
1011浏览 • 1回复 待解决
DevEco Studio如何调出快捷工具栏
8975浏览 • 1回复 待解决
HarmonyOS 列表视频全屏播放实现
1193浏览 • 1回复 待解决
HarmonyOS Video组件能否设置自定义header
1098浏览 • 1回复 待解决
HarmonyOS 跟随键盘的工具栏如何实现
473浏览 • 1回复 待解决