微信小程序方法:
<video class="my-video1" id="myVideo1" bindfullscreenchange="screenChange" src="{{ossPath+'video/dunhuang-video202201051033.mp4'}}" controls='controls'></video>
点击进入全屏:
showVideo1() {
let videoContext = wx.createVideoContext('myVideo1'); //获取video的dom
videoContext.requestFullScreen({ direction: 90 });
videoContext.play() //视频播放
},
另一种方法
<video bindtap="fullscreen" id="myVideo" style="width: 100rpx; height: 100rpx;" src="http://jixiequan-miniapp.oss-cn-beijing.aliyuncs.com/attach/video/2023/08/30/fd618202308301522291090.mp4"/>
//按钮事件
fullscreen() {
let videoContext = wx.createVideoContext('myVideo'); //获取video的dom
videoContext.requestFullScreen({ direction: 90 });
videoContext.play() //视频播放
}
监听是否退出或进入全屏:(在video上绑定bindfullscreenchange事件)文章来源:https://www.toymoban.com/news/detail-685193.html
screenChange(e) {
let fullScreen = e.detail.fullScreen //值true为进入全屏,false为退出全屏
let videoContext = wx.createVideoContext('myVideo1');
},
h5方法:
点击进入全屏:文章来源地址https://www.toymoban.com/news/detail-685193.html
<video id="product1" controls="false" webview.allowsInlineMediaPlayback=YES; x5-video-player-type="h5" x5-video-player-fullscreen="true" x5-video-orientation="portraint" :src="videoPath+'qhtalent202112/product-info.mp4'">
</video>
//判断进入退出全屏
checkIsFullScreen() {
var isFullScreen = document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen;
return isFullScreen == undefined ? false : isFullScreen;
},
// 全屏
Screen(element) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
} else if (element.oRequestFullscreen) {
element.oRequestFullscreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullScreen();
} else {
var requestFullscreen =
document.documentElement.requestFullscreen ||
document.documentElement.webkitRequestFullscreen ||
document.documentElement.mozRequestFullscreen ||
document.documentElement.requestFullScreen ||
document.documentElement.webkitRequestFullScreen ||
document.documentElement.mozRequestFullScreen;
if (requestFullscreen) {
requestFullscreen.call(document.documentElement);
}
//ios不处理,自动就会全屏
}
element.play()
},
//点读笔播放视频
productBtn() {
let product1 = document.getElementById('product1')
product1.play()
this.Screen(product1)
},
document.addEventListener('fullscreenchange', () => {
if (this.checkIsFullScreen()) {
this.productPlay = true
console.log("进入全屏");
} else {
console.log("退出全屏");
this.productPlay = false
document.getElementById('product1').pause()
}
});
到了这里,关于video 按钮全屏的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!