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

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

HarmonyOS
2024-10-08 11:15:37
浏览
收藏 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)  
  }  
}
分享
微博
QQ
微信
回复
2024-10-08 17:04:20
相关问题
如何自定义Video组件控制样式
2852浏览 • 1回复 待解决
HarmonyOS Web组件如何实现视频全屏播放
1172浏览 • 1回复 待解决
DevEco Studio如何调出快捷工具栏
8305浏览 • 1回复 待解决
HarmonyOS Web全屏播放适配
392浏览 • 1回复 待解决
HarmonyOS 列表视频全屏播放实现
636浏览 • 1回复 待解决
HarmonyOS 跟随键盘的工具栏如何实现
67浏览 • 1回复 待解决
HarmonyOS Web加载的PDF如何去除工具栏
220浏览 • 1回复 待解决