I just found out some differences between error handling when loading a video using the src tag of the <video> element and processing errors when loading a video using the <source> element.
For example, if I try to download a video stream that is not found (HTTP 404) using the src tag of the video element, an event is fired and the element stores error data:
HTML
<video src="http://not.found.url"></video>
Js
var video = document.querySelector('video'); video.addEventListener('error', function(evt) { console.log(evt.target.error);
The video element stores the MediaError object in error :
error: { code: 4, message: 'MEDIA_ELEMENT_ERROR: Format error' }
However, when I try to load the same video stream using the source element:
HTML
<video> <source src="http://not.found.url"> </video>
Js
var video = document.querySelector('video'); var source = document.querySelector('source'); video.addEventListener('error', function(evt) { // This event is not triggered console.log(evt.target.error); // null }); source.addEventListener('error', function(evt) { console.log(evt.target.error); // null }); video.load();
The error handler of the source element is the only one that catches the error, but error data is not stored anywhere. Neither the video element nor the source element store the error object, so I can say that the error was caused, but I can not find out the type of this error.
I would like to use the source element and be able to determine if the cause of the error is an invalid video format, 404 resource, or any other reason.
Is it possible?
Thanks!