From 12e542b7f415f508a2b6f2cffa63dc85f227b9c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rblom?= Date: Sun, 21 Jul 2013 22:02:23 +0200 Subject: [PATCH] html5video: detect errors on the source element (tested in ff & opera) --- src/webui/static/tv.js | 57 ++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/webui/static/tv.js b/src/webui/static/tv.js index 0b1bde84..61824d50 100644 --- a/src/webui/static/tv.js +++ b/src/webui/static/tv.js @@ -150,6 +150,9 @@ tv.ui.VideoPlayer = Ext.extend(Ext.Panel, (function() { html : "Your browser doesn't support html5 video" }); + this.source = this.video.createChild({tag: 'source'}); + this.source.dom.addEventListener('error', this.error.bind(this)); + this.stop(); var self = this; @@ -157,7 +160,7 @@ tv.ui.VideoPlayer = Ext.extend(Ext.Panel, (function() { this.video.dom.addEventListener('loadeddata', function() { setTimeout(function() { self.play(); - }, self.bufferLength); //buffer 3000ms + }, self.bufferLength); }); } } @@ -207,38 +210,38 @@ tv.ui.VideoPlayer = Ext.extend(Ext.Panel, (function() { }, error: function(e) { - var url = this.video.dom.src; + var url = this.source.dom.src; if(url && url != document.location.href) { this.body.removeClass('tv-video-loading'); this.body.removeClass('tv-video-idle'); this.body.addClass('tv-video-error'); this.video.hide(); + this.message.update('An unknown error occurred.'); + var err = e.target.error; - switch (err.code) { - case err.MEDIA_ERR_ABORTED: - this.message.update('You aborted the video playback.'); - break; - - case err.MEDIA_ERR_NETWORK: - this.message.update('A network error caused the video ' + - 'download to fail part-way.'); - break; - case err.MEDIA_ERR_DECODE: - this.message.update('The video playback was aborted due to ' + - 'a corruption problem or because the video ' + - 'used features your browser did not support.'); - break; - case err.MEDIA_ERR_SRC_NOT_SUPPORTED: - this.message.update('The video could not be loaded, either because ' + - 'the server or network failed or because the ' + - 'format is not supported.'); - break; - default: - this.message.update('An unknown error occurred.'); - break; + if(err) { + switch (err.code) { + case err.MEDIA_ERR_ABORTED: + this.message.update('You aborted the video playback.'); + break; + + case err.MEDIA_ERR_NETWORK: + this.message.update('A network error caused the video ' + + 'download to fail part-way.'); + break; + case err.MEDIA_ERR_DECODE: + this.message.update('The video playback was aborted due to ' + + 'a corruption problem or because the video ' + + 'used features your browser did not support.'); + break; + case err.MEDIA_ERR_SRC_NOT_SUPPORTED: + this.message.update('The video could not be loaded, either because ' + + 'the server or network failed or because the ' + + 'format is not supported.'); + break; + } } - this.message.show(); } }, @@ -248,7 +251,7 @@ tv.ui.VideoPlayer = Ext.extend(Ext.Panel, (function() { this.body.removeClass('tv-video-loading'); this.body.removeClass('tv-video-error'); this.body.addClass('tv-video-idle'); - this.video.dom.src = ''; + this.source.dom.src = ''; this.video.dom.load(); }, @@ -279,7 +282,7 @@ tv.ui.VideoPlayer = Ext.extend(Ext.Panel, (function() { this.body.removeClass('tv-video-error'); this.body.addClass('tv-video-loading'); - this.video.dom.src = this._getUrl(chid, params); + this.source.dom.src = this._getUrl(chid, params); this.video.dom.load(); } };