DOM Exception 11 when calling webkitEnterFullscreen()
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);
精彩评论