开发者

DOM Exception 11 when calling webkitEnterFullscreen()

开发者 https://www.devze.com 2023-04-01 12:47 出处:网络
What does the except开发者_开发知识库ion mean? How can I fix it? I am using the latest Google Chrome for Ubuntu.INVALID_STATE_ERR: DOM Exception 11 can occur when a call to webkitEnterFullscreen is ma

What does the except开发者_开发知识库ion mean? How can I fix it? I am using the latest Google Chrome for Ubuntu.


INVALID_STATE_ERR: DOM Exception 11 can occur when a call to webkitEnterFullscreen is made before the video element has received its asset's metadata. The simplest solution is to defer the invocation of webkitEnterFullscreen by putting it in a callback function assigned to the video's loadedmetadata event.

In a mobile environment, you need to take things a step further by attaching that call to a touchable element so that it is user initiated since play and fullscreen actions must be driven by user interaction in mobile environments.

The code should look kind of like this:

var video, play, fullscreen;

video = document.createElement('video');
video.src = 'my_cool_video.mp4';
video.addEventListener('loadedmetadata', function () {
    fullscreen.disabled = false;
}, false);

play = document.createElement('button');
play.innerHTML = 'PLAY';
play.addEventListener('click', function () {
    video.play();
}, false);

fullscreen = document.createElement('button');
fullscreen.innerHTML = 'FULLSCREEN';
fullscreen.disabled = true;
fullscreen.addEventListener('click', function () {
    video.webkitEnterFullscreen();
}, false);

document.body.appendChild(video);
document.body.appendChild(play);
documnet.body.appendChild(fullscreen);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号