Cordova插件“cordova-plugin-screen-orientation”设置移动端横屏播放video视频

首次,下载“cordova-plugin-screen-orientation”插件

cordova plugin add cordova-plugin-screen-orientation

新建一个video标签,设置id="video"

<video class="video" slot="video" id="video" controls playsinline>

在mounted中给video元素添加监听,监听屏幕状态,代码如下:

(document as any)
  .getElementById("video")
    .addEventListener("webkitfullscreenchange", () => {
      if ((document as any).webkitIsFullScreen) {
        (cordova as any).plugins.screenorientation.setOrientation(
          "landscape"
        );
        console.log("全屏播放横屏");
      } else {
        (cordova as any).plugins.screenorientation.setOrientation("portrait");
          console.log("退出全屏播放竖屏");
       }
    });

猜你喜欢

转载自blog.csdn.net/weixin_46653941/article/details/120140062