Created
November 16, 2015 21:14
-
-
Save nifl/c5b9e8f733e923b24cfe to your computer and use it in GitHub Desktop.
Error handling for HTML5 Video http://jsbin.com/jijeke/1/edit?html,css,output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vid.addEventListener('error', function(evt) { | |
logEvent(evt,'red'); | |
}, false); | |
... | |
function logEvent(evt, color) { | |
switch (evt.type) { | |
... | |
case 'error': | |
var error = document.querySelector('video').error; | |
switch (error.code) { | |
case error.MEDIA_ERR_ABORTED: | |
note.innerHTML = "fetching aborted at the user's request"; | |
break; | |
case error.MEDIA_ERR_NETWORK: | |
note.innerHTML = "a network error caused the browser to stop fetching the media"; | |
break; | |
case error.MEDIA_ERR_DECODE: | |
note.innerHTML = "an error occurred while decoding the media"; | |
break; | |
case error.MEDIA_ERR_SRC_NOT_SUPPORTED: | |
note.innerHTML = "the media indicated by the src | |
attribute was not suitable"; | |
break; | |
default: | |
note.innerHTML = "an error occurred"; | |
break; | |
} | |
break; | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment