首次,下载“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("退出全屏播放竖屏");
}
});