onsa
12/17/2016 - 12:05 AM

Handle errors when a media file is being streamed.

Handle errors when a media file is being streamed.

video.addEventListener('error', function(event) {
	logEvent(event,'red');
}, false);

function logEvent(event, color) {
		switch (event.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;
    }
}