I want to add some error handling to a simple HTML5 video element. I use this piece of code that appears everywhere online :
Js
function playbackFailed(e) {
HTML
<video id="a" src="tgif.vid" autoplay controls onerror="playbackFailed(event)" poster="http://img.rasset.ie/000736d2-512.jpg" width="620" height="400"></video>
The above works fine, and when the page loads, I get an instant warning window.
However, if I do not have the "src" attribute and instead use the <source> in the <video> element, "onerror (event)" does not fire? Layout Example:
<video id="b" autoplay controls onerror="playbackFailed(event)" poster="http://img.rasset.ie/000736d2-512.jpg" width="620" height="400"> <source src="tgif.vid"> </video>
Note. I gave both elements of the video above the identifiers "a" and "b".
Can someone explain why in the following code:
<script> var a = document.getElementById('a'); var b = document.getElementById('b'); a.addEventListener('error', function(e){alert('error event on a')}); b.addEventListener('error', function(e){alert('error event on b')}); </script>
I get a warning only for "a" and not "b"
I need to use the <source> , since I will have several types of media for different devices, etc.
Thanks for any answers / comments.
S
sidarcy
source share