HarmonyOS video如何横屏播放?

HarmonyOS video如何横屏播放?


HarmonyOS
2024-10-14 09:47:06
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

请参考以下demo:

import window from '@ohos.window'  
@Entry  
@Component  
struct VideoCreateComponent {  
  @State videoSrc: Resource = $rawfile('video1.mp4')  
  @State previewUri: Resource = $r('app.media.app_icon')  
  @State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X  
  @State isAutoPlay: boolean = true  
  @State showControls: boolean = true  
  controller: VideoController = new VideoController()  
  // 设置窗口方向  
  setR(orientation:number){  
    window.getLastWindow(getContext(this)).then((win) => {  
      win.setPreferredOrientation(orientation).then((data) => {  
        console.log('setWindowOrientation: '+orientation+' Succeeded. Data: ' + JSON.stringify(data));  
      }).catch((err:string) => {  
        console.log('setWindowOrientation: Failed. Cause: ' + JSON.stringify(err));  
      });  
    }).catch((err:string) => {  
      console.log( 'setWindowOrientation: Failed to obtain the top window. Cause: ' + JSON.stringify(err));  
    });  
  }  
  build() {  
    Column() {  
      Video({  
        src: this.videoSrc,  
        previewUri: this.previewUri,  
        currentProgressRate: this.curRate,  
        controller: this.controller  
      })  
        .objectFit(ImageFit.Contain)  
        .width('100%')  
        .height(600)  
        .autoPlay(this.isAutoPlay)  
        .controls(this.showControls)  
        .onFullscreenChange((e ?: FullObject) =>{  
          if (e?.fullscreen) {  
            this.setR(4)  
          } else {  
            this.setR(1)  
          }  
        })  
      Row() {  
        Button('Fullscreen').onClick(() => {  
          this.controller.requestFullscreen(true);  
        }).margin(5)  
      }  
    }  
  }  
}  
interface FullObject {  
  fullscreen: boolean;  
}
分享
微博
QQ
微信
回复
2024-10-14 16:50:51
相关问题
HarmonyOS 播放问题
327浏览 • 1回复 待解决
openharmony jsFA 如何显示?
7275浏览 • 1回复 待解决
如何获取当前是还是竖啊?
4920浏览 • 1回复 待解决
HarmonyOS 后布局问题
20浏览 • 1回复 待解决
HarmonyOS 相机旋转拍照问题
234浏览 • 1回复 待解决
HarmonyOS video设置加载图闪
284浏览 • 1回复 待解决
如何设置屏幕方向为
1243浏览 • 1回复 待解决
应用如何适配华为悬浮窗?
2630浏览 • 1回复 待解决
HarmonyOS Video无法播放m3u8
302浏览 • 1回复 待解决
page页面如何设置为显示
1700浏览 • 1回复 待解决