HarmonyOS 视频播放组件不支持横屏播放,有没有横屏播放解决方案

HarmonyOS
2024-12-25 09:12:41
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

参考示例:

import window from '@ohos.window'

@Entry
@Component
struct VideoCreateComponent {
  @State videoSrc: Resource = $rawfile('VID_1721101546_005.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;
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-25 10:44:01


相关问题
HarmonyOS 播放问题
1051浏览 • 1回复 待解决
HarmonyOS video如何播放
775浏览 • 1回复 待解决
HarmonyOS 音频播放组件解决方案
640浏览 • 1回复 待解决
HarmonyOS webView视频展示
534浏览 • 1回复 待解决
HarmonyOS 如何让app支持
616浏览 • 1回复 待解决
HarmonyOS 播放视频的时候禁止息
476浏览 • 1回复 待解决
openharmony jsFA 如何显示?
7764浏览 • 1回复 待解决
HarmonyOS webrtc同功能的解决方案
466浏览 • 1回复 待解决
HarmonyOS 后布局问题
905浏览 • 1回复 待解决
HarmonyOS webview是否支持视频播放
462浏览 • 1回复 待解决