Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Created August 4, 2012 00:08
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilmoore/3252894 to your computer and use it in GitHub Desktop.
Save wilmoore/3252894 to your computer and use it in GitHub Desktop.
HTML5 Video Playback Error Handling POC
<p><video src="tgif.vid" autoplay controls onerror="failed(event)"></video></p>
<p><a href="tgif.vid">Download the video file</a>.</p>
<script>
function failed(e) {
// video playback failed - show a message saying why
switch (e.target.error.code) {
case e.target.error.MEDIA_ERR_ABORTED:
alert('You aborted the video playback.');
break;
case e.target.error.MEDIA_ERR_NETWORK:
alert('A network error caused the video download to fail part-way.');
break;
case e.target.error.MEDIA_ERR_DECODE:
alert('The video playback was aborted due to a corruption problem or because the video used features your browser did not support.');
break;
case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
alert('The video could not be loaded, either because the server or network failed or because the format is not supported.');
break;
default:
alert('An unknown error occurred.');
break;
}
}
</script>
@wilmoore
Copy link
Author

wilmoore commented Aug 4, 2012

@plonknimbuzz
Copy link

you save my day bro. thank you very much

@Brendan-Iwobi
Copy link

This is absolutely beatiful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment