有时候要判断当前视频流分辨率是否改变,比如是否切换分辨率成功等,用resize 事件可以实现,
<p data-content="resolution"></p>
<video src="https://bug1250345.bmoattachments.org/attachment.cgi?id=8722238"></video>
document.querySelector('video').addEventListener('resize', (e) => {
document.querySelector('[data-content="resolution"]').textContent = [
e.target.videoWidth,
e.target.videoHeight
].join('x');
});
其实起作用的就那么一句
document.querySelector('video').addEventListener('resize', (e) => {
if(e.target.videoWidth > e.target.videoHeight) {
console.log("横屏状态");
}
if(e.target.videoHeight > e.target.videoWidth) {
console.log("竖屏状态");
}
});
参考:Detecting video resolution changes – JavaScripthttps://javascript.tutorialink.com/detecting-video-resolution-changes/
|