Changeset 1288


Ignore:
Timestamp:
09/19/10 19:05:39 (3 years ago)
Author:
zach
Message:
  • Fixing error display issue
Location:
trunk/html5
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/html5/bin-debug/jwplayer.html5.js

    r1285 r1288  
    265265                        if (_model.plugins.object[pluginName].getDisplayElement !== undefined) { 
    266266                                if (_hasPosition(_model.plugins.config[pluginName].position)) { 
    267                                         if (_model.plugins.object[pluginName].getDisplayElement().parentElement === null) { 
     267                                        if (_model.plugins.object[pluginName].getDisplayElement().parentNode === null) { 
    268268                                                _wrapper.appendChild(_model.plugins.object[pluginName].getDisplayElement()); 
    269269                                        } 
     
    277277                 
    278278                function _overlayComponentResizer(pluginName, zIndex) { 
    279                         if (_model.plugins.object[pluginName].getDisplayElement().parentElement === null) { 
     279                        if (_model.plugins.object[pluginName].getDisplayElement().parentNode === null) { 
    280280                                _box.appendChild(_model.plugins.object[pluginName].getDisplayElement()); 
    281281                        } 
     
    537537                var _elements = {}; 
    538538                var _ready = false; 
    539                 var _fadeOutTimeout; 
    540539                 
    541540                 
     
    595594                 
    596595                function _fadeOut() { 
    597                         _wrapper.style.opacity = 1; 
    598                         if (_fadeOutTimeout !== undefined) { 
    599                                 clearTimeout(_fadeOutTimeout); 
    600                         } 
    601                         _fadeOutTimeout = setTimeout(function() { 
    602                                 jwplayer.html5.utils.fadeTo(_wrapper, 0, 0.1, 1); 
    603                                 _fadeOutTimeout = undefined; 
    604                         }, 2000); 
     596                        jwplayer.html5.utils.cancelAnimation(_wrapper); 
     597                        jwplayer.html5.utils.fadeTo(_wrapper, 0, 0.1, 1, 2); 
    605598                } 
    606599                 
     
    13661359 * @version 1.0 
    13671360 */ 
    1368 (function(jwplayer) {    
     1361(function(jwplayer) { 
    13691362        _css = jwplayer.html5.utils.css; 
    13701363         
     
    13911384                var _bufferInterval = _api.skin.getComponentSettings("display").bufferinterval === undefined ? 100 : parseInt(_api.skin.getComponentSettings("display").bufferinterval, 10); 
    13921385                var _elements = { 
    1393                                 display: { 
    1394                                         style: { 
    1395                                                 cursor: "pointer" 
    1396                                         }, 
    1397                                         click: _displayClickHandler 
     1386                        display: { 
     1387                                style: { 
     1388                                        cursor: "pointer" 
    13981389                                }, 
    1399                                 display_icon: { 
    1400                                         style: { 
    1401                                                 cursor: "pointer", 
    1402                                                 position: "absolute", 
    1403                                                 top: ((_api.skin.getSkinElement("display", "background").height - _api.skin.getSkinElement("display", "playIcon").height) / 2), 
    1404                                                 left: ((_api.skin.getSkinElement("display", "background").width - _api.skin.getSkinElement("display", "playIcon").width) / 2), 
    1405                                                 border: 0, 
    1406                                                 margin: 0, 
    1407                                                 padding: 0 
    1408                                         } 
    1409                                 }, 
    1410                                 display_iconBackground: { 
    1411                                         style: { 
    1412                                                 cursor: "pointer", 
    1413                                                 position: "absolute", 
    1414                                                 top: ((_height - _api.skin.getSkinElement("display", "background").height) / 2), 
    1415                                                 left: ((_width - _api.skin.getSkinElement("display", "background").width) / 2), 
    1416                                                 border: 0, 
    1417                                                 backgroundImage: (["url(", _api.skin.getSkinElement("display", "background").src, ")"]).join(""), 
    1418                                                 width: _api.skin.getSkinElement("display", "background").width, 
    1419                                                 height: _api.skin.getSkinElement("display", "background").height, 
    1420                                                 margin: 0, 
    1421                                                 padding: 0 
    1422                                         } 
    1423                                 }, 
    1424                                 display_image: { 
    1425                                         style: { 
    1426                                                 display: "block", 
    1427                                                 width: _width, 
    1428                                                 height: _height, 
    1429                                                 position: "absolute", 
    1430                                                 cursor: "pointer", 
    1431                                                 left: 0, 
    1432                                                 top: 0, 
    1433                                                 margin: 0, 
    1434                                                 padding: 0, 
    1435                                                 textDecoration: "none" 
    1436                                         } 
    1437                                 } 
    1438                         }; 
     1390                                click: _displayClickHandler 
     1391                        }, 
     1392                        display_icon: { 
     1393                                style: { 
     1394                                        cursor: "pointer", 
     1395                                        position: "absolute", 
     1396                                        top: ((_api.skin.getSkinElement("display", "background").height - _api.skin.getSkinElement("display", "playIcon").height) / 2), 
     1397                                        left: ((_api.skin.getSkinElement("display", "background").width - _api.skin.getSkinElement("display", "playIcon").width) / 2), 
     1398                                        border: 0, 
     1399                                        margin: 0, 
     1400                                        padding: 0 
     1401                                } 
     1402                        }, 
     1403                        display_iconBackground: { 
     1404                                style: { 
     1405                                        cursor: "pointer", 
     1406                                        position: "absolute", 
     1407                                        top: ((_height - _api.skin.getSkinElement("display", "background").height) / 2), 
     1408                                        left: ((_width - _api.skin.getSkinElement("display", "background").width) / 2), 
     1409                                        border: 0, 
     1410                                        backgroundImage: (["url(", _api.skin.getSkinElement("display", "background").src, ")"]).join(""), 
     1411                                        width: _api.skin.getSkinElement("display", "background").width, 
     1412                                        height: _api.skin.getSkinElement("display", "background").height, 
     1413                                        margin: 0, 
     1414                                        padding: 0 
     1415                                } 
     1416                        }, 
     1417                        display_image: { 
     1418                                style: { 
     1419                                        display: "block", 
     1420                                        width: _width, 
     1421                                        height: _height, 
     1422                                        position: "absolute", 
     1423                                        cursor: "pointer", 
     1424                                        left: 0, 
     1425                                        top: 0, 
     1426                                        margin: 0, 
     1427                                        padding: 0, 
     1428                                        textDecoration: "none" 
     1429                                } 
     1430                        }, 
     1431                        display_text: { 
     1432                                style: { 
     1433                                        position: "relative", 
     1434                                        top: "50%", 
     1435                                        opacity: 0.8, 
     1436                                        backgroundColor: "black", 
     1437                                        color: "white", 
     1438                                        display: "none", 
     1439                                        textAlign: "center", 
     1440                                        fontFamily: "Arial,sans-serif", 
     1441                                        padding: "0 5px", 
     1442                                        fontSize: 14 
     1443                                } 
     1444                        } 
     1445                }; 
    14391446                _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_PLAYER_STATE, _stateHandler); 
    14401447                _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_MEDIA_MUTE, _stateHandler); 
    14411448                _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_PLAYLIST_ITEM, _stateHandler); 
    1442                 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_MEDIA_ERROR, function(obj) { 
    1443                 }); 
     1449                _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_ERROR, _errorHandler); 
    14441450                _setupDisplay(); 
    1445                  
    14461451                 
    14471452                function _setupDisplay() { 
    14481453                        _display.display = createElement("div", "display"); 
     1454                        _display.display_text = createElement("div", "display_text"); 
     1455                        _display.display.appendChild(_display.display_text); 
    14491456                        _display.display_image = createElement("div", "display_image"); 
    14501457                        _display.display_icon = createElement("div", "display_icon"); 
     
    14841491                        _css(_element, _elements[element].style); 
    14851492                        return _element; 
    1486                 } 
    1487                  
    1488                 function _getStyle(element) { 
    1489                         var result = ''; 
    1490                         for (var style in _elements[element].style) { 
    1491                                 result += style + ":" + _elements[element].style[style] + ";"; 
    1492                         } 
    1493                         if (result === '') { 
    1494                                 return ' '; 
    1495                         } 
    1496                         return ' style="' + result + '" '; 
    14971493                } 
    14981494                 
     
    15511547                } 
    15521548                 
    1553                 function _stateHandler(obj) { 
     1549                function _errorHandler(evt){ 
     1550                        _hideDisplayIcon(); 
     1551                        _display.display_text.innerHTML = "<p>"+evt.error+"</p>"; 
     1552                        _show(_display.display_text); 
     1553                        _display.display_text.style.top = ((_height -  _display.display_text.getBoundingClientRect().height) / 2) + "px"; 
     1554                } 
     1555                 
     1556                function _stateHandler(evt) { 
     1557                        _hide(_display.display_text); 
    15541558                        if (_rotationInterval !== undefined) { 
    15551559                                clearInterval(_rotationInterval); 
     
    17961800                var _api = api; 
    17971801                var _settings = jwplayer.utils.extend({}, _defaults, config); 
    1798                 var _interval; 
    17991802                 
    18001803                var _logo = document.createElement("img"); 
    1801                  
    18021804                _logo.id = _api.id + "_jwplayer_logo"; 
     1805                _css(_logo, _getStyle()); 
    18031806                 
    18041807                _logo.onload = function(evt) { 
    18051808                        _settings.width = _logo.width; 
    18061809                        _settings.height = _logo.height; 
    1807                          
    1808                         _css(_logo, _getStyle()); 
    1809                          
     1810                                                 
    18101811                        _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_PLAYER_STATE, _stateHandler); 
    18111812                }; 
     
    18281829                                height: _settings.height, 
    18291830                                textDecoration: "none", 
    1830                                 position: "absolute" 
     1831                                position: "absolute", 
     1832                                display: "none" 
    18311833                        }; 
    18321834                        var positions = _settings.position.toLowerCase().split("-"); 
     
    18541856                                case jwplayer.api.events.state.BUFFERING: 
    18551857                                        _logo.style.opacity = _settings.out; 
    1856                                         setTimeout(jwplayer.html5.utils.fadeTo(_logo, 0, 0.1, _logo.style.opacity), _settings.timeout * 1000); 
     1858                                        jwplayer.html5.utils.fadeTo(_logo, 0, 0.1, parseFloat(_logo.style.opacity), _settings.timeout); 
    18571859                                        break; 
    18581860                                case jwplayer.api.events.state.PAUSED: 
     
    18601862                                case jwplayer.api.events.state.IDLE: 
    18611863                                        break; 
     1864                                case jwplayer.api.events.state.PLAYING: 
     1865                                        break; 
    18621866                                default: 
    1863                                         setTimeout(jwplayer.html5.utils.fadeTo(_logo, 0, 0.1, _logo.style.opacity), _settings.timeout * 1000); 
     1867                                        jwplayer.html5.utils.fadeTo(_logo, 0, 0.1, parseFloat(_logo.style.opacity), _settings.timeout); 
    18641868                                        break; 
    18651869                        } 
     
    19281932                var _start = false; 
    19291933                var hasChrome = false; 
     1934                var _currentItem; 
     1935                var _sourceError = 0; 
    19301936                 
    19311937                function _getState() { 
     
    19531959                                _model.state = newstate; 
    19541960                                _state = newstate; 
     1961                                var _sendComplete = false; 
    19551962                                if (newstate == jwplayer.api.events.state.IDLE) { 
    19561963                                        _clearInterval(); 
    1957                                         _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE); 
     1964                                        if (_model.position >= _model.duration && (_model.position || _model.duration)) { 
     1965                                                _sendComplete = true; 
     1966                                        } 
    19581967                                         
    19591968                                        if (_container.style.display != 'none') { 
     
    19661975                                        newstate: newstate 
    19671976                                }); 
     1977                                if (_sendComplete) { 
     1978                                        _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE); 
     1979                                } 
    19681980                        } 
    19691981                        _stopped = false; 
     
    19771989                                duration: event.target.duration 
    19781990                        }; 
    1979                         if (_model.duration === 0) { 
    1980                                 _model.duration = event.target.duration; 
     1991                        if (_model.duration === 0 || isNaN(_model.duration)) { 
     1992                                _model.duration = Math.round(event.target.duration * 10) / 10; 
    19811993                        } 
    19821994                        _model.playlist[_model.item] = jwplayer.utils.extend(_model.playlist[_model.item], meta); 
     
    19932005                         
    19942006                        if (event !== undefined && event.target !== undefined) { 
    1995                                 if (_model.duration === 0) { 
    1996                                         _model.duration = event.target.duration; 
    1997                                 } 
    1998                                  
     2007                                if (_model.duration === 0 || isNaN(_model.duration)) { 
     2008                                        _model.duration = Math.round(event.target.duration * 10) / 10 
     2009                                } 
     2010                                if (!_start && _container.readyState > 0) { 
     2011                                        _setState(jwplayer.api.events.state.PLAYING); 
     2012                                } 
    19992013                                if (_state == jwplayer.api.events.state.PLAYING) { 
    20002014                                        if (!_start && _container.readyState > 0) { 
     
    20282042                        } 
    20292043                         
    2030                         if (_bufferFull === false) { 
     2044                        if (_bufferFull === false && _state == jwplayer.api.events.state.BUFFERING) { 
    20312045                                _bufferFull = true; 
    20322046                                _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER_FULL); 
     
    20632077                 
    20642078                function _errorHandler(event) { 
    2065                         _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_ERROR, event.target); 
     2079                        _stop(); 
     2080                        var message = "There was an error: "; 
     2081                        if (event.target.error || event.target.parentNode.error) { 
     2082                                var element = event.target.error === undefined ? event.target.parentNode.error : event.target.error; 
     2083                                switch (element.code) { 
     2084                                        case element.MEDIA_ERR_ABORTED: 
     2085                                                message = "You aborted the video playback: "; 
     2086                                                break; 
     2087                                        case element.MEDIA_ERR_NETWORK: 
     2088                                                message = "A network error caused the video download to fail part-way: "; 
     2089                                                break; 
     2090                                        case element.MEDIA_ERR_DECODE: 
     2091                                                message = "The video playback was aborted due to a corruption problem or because the video used features your browser did not support: "; 
     2092                                                break; 
     2093                                        case element.MEDIA_ERR_SRC_NOT_SUPPORTED: 
     2094                                                message = "The video could not be loaded, either because the server or network failed or because the format is not supported: "; 
     2095                                                break; 
     2096                                        default: 
     2097                                                message = "An unknown error occurred: "; 
     2098                                                break; 
     2099                                } 
     2100                        } else if (event.target.tagName.toLowerCase() == "source") { 
     2101                                _sourceError++; 
     2102                                if (_sourceError != _currentItem.levels.length) { 
     2103                                        return; 
     2104                                } 
     2105                                message = "The video could not be loaded, either because the server or network failed or because the format is not supported: "; 
     2106                        } 
     2107                         
     2108                        message += joinFiles(); 
     2109                        _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_ERROR, { 
     2110                                error: message 
     2111                        }); 
     2112                        return; 
     2113                } 
     2114                 
     2115                function joinFiles() { 
     2116                        var result = ""; 
     2117                        for (var sourceIndex in _currentItem.levels) { 
     2118                                var sourceModel = _currentItem.levels[sourceIndex]; 
     2119                                var source = _container.ownerDocument.createElement("source"); 
     2120                                result += jwplayer.html5.utils.getAbsolutePath(sourceModel.file); 
     2121                                if (sourceIndex < (_currentItem.levels.length - 1)) { 
     2122                                        result += ", "; 
     2123                                } 
     2124                        } 
     2125                        return result; 
    20662126                } 
    20672127                 
     
    20762136                                } 
    20772137                                _container.play(); 
    2078                                 _setState(jwplayer.api.events.state.PLAYING); 
    20792138                                _startInterval(); 
    20802139                        } 
     
    20972156                 
    20982157                /** Stop playback and loading of the video. **/ 
    2099                 this.stop = function() { 
     2158                function _stop() { 
    21002159                        _stopped = true; 
    21012160                        _container.pause(); 
     
    21032162                        _model.position = 0; 
    21042163                        _setState(jwplayer.api.events.state.IDLE); 
    2105                 }; 
    2106                  
     2164                } 
     2165                 
     2166                this.stop = _stop; 
    21072167                 
    21082168                /** Change the video's volume level. **/ 
     
    21552215                this.load = function(playlistItem) { 
    21562216                        _embed(playlistItem); 
    2157                          
     2217                        _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_LOADED); 
    21582218                        _bufferFull = false; 
    21592219                        _bufferingComplete = false; 
    21602220                        _start = false; 
     2221                        _setState(jwplayer.api.events.state.BUFFERING); 
     2222                         
    21612223                        setTimeout(function() { 
    2162                                 _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_LOADED); 
    2163                                 _setState(jwplayer.api.events.state.BUFFERING); 
    21642224                                _positionHandler(); 
    21652225                        }, 25); 
     
    21672227                 
    21682228                _embed = function(playlistItem) { 
     2229                        _currentItem = playlistItem; 
    21692230                        var vid = document.createElement("video"); 
    21702231                        vid.preload = "none"; 
    21712232                        vid.loop = _model.config.repeat; 
     2233                        _sourceError = 0; 
    21722234                        for (var sourceIndex in playlistItem.levels) { 
    21732235                                var sourceModel = playlistItem.levels[sourceIndex]; 
     
    26812743        }; 
    26822744         
    2683         jwplayer.html5.utils.fadeTo = function(domelement, endAlpha, time, startAlpha, startTime) { 
     2745        jwplayer.html5.utils.cancelAnimation = function(domelement) { 
     2746                delete _animations[domelement]; 
     2747        }; 
     2748         
     2749        jwplayer.html5.utils.fadeTo = function(domelement, endAlpha, time, startAlpha, delay, startTime) { 
    26842750                // Interrupting 
    26852751                if (_animations[domelement] != startTime && startTime !== undefined) { 
     
    26872753                } 
    26882754                var currentTime = new Date().getTime(); 
     2755                if (startTime > currentTime) { 
     2756                        setTimeout(function() { 
     2757                                jwplayer.html5.utils.fadeTo(domelement, endAlpha, time, startAlpha, 0, startTime); 
     2758                        }, startTime - currentTime); 
     2759                } 
     2760                domelement.style.display = "block"; 
    26892761                if (startAlpha === undefined) { 
    26902762                        startAlpha = domelement.style.opacity === "" ? 1 : domelement.style.opacity; 
    26912763                } 
    2692                 if (typeof startAlpha == "string") { 
    2693                         startAlpha = parseInt(startAlpha, 10); 
    2694                 } 
    26952764                if (domelement.style.opacity == endAlpha && domelement.style.opacity !== "" && startTime !== undefined) { 
     2765                        if (endAlpha === 0) { 
     2766                                domelement.style.display = "none"; 
     2767                        } 
    26962768                        return; 
    26972769                } 
     
    26992771                        startTime = currentTime; 
    27002772                        _animations[domelement] = startTime; 
     2773                } 
     2774                if (delay === undefined) { 
     2775                        delay = 0; 
    27012776                } 
    27022777                var percentTime = (currentTime - startTime) / (time * 1000); 
     
    27102785                } 
    27112786                domelement.style.opacity = alpha; 
     2787                if (delay > 0) { 
     2788                        _animations[domelement] = startTime + delay * 1000; 
     2789                        jwplayer.html5.utils.fadeTo(domelement, endAlpha, time, startAlpha, 0, _animations[domelement]); 
     2790                        return; 
     2791                } 
    27122792                setTimeout(function() { 
    2713                         jwplayer.html5.utils.fadeTo(domelement, endAlpha, time, startAlpha, startTime); 
     2793                        jwplayer.html5.utils.fadeTo(domelement, endAlpha, time, startAlpha, 0, startTime); 
    27142794                }, 10); 
    2715         }; 
    2716          
     2795        };       
    27172796})(jwplayer); 
    27182797/** 
  • trunk/html5/src/html5/jwplayer.html5.display.js

    r1278 r1288  
    55 * @version 1.0 
    66 */ 
    7 (function(jwplayer) {    
     7(function(jwplayer) { 
    88        _css = jwplayer.html5.utils.css; 
    99         
     
    3030                var _bufferInterval = _api.skin.getComponentSettings("display").bufferinterval === undefined ? 100 : parseInt(_api.skin.getComponentSettings("display").bufferinterval, 10); 
    3131                var _elements = { 
    32                                 display: { 
    33                                         style: { 
    34                                                 cursor: "pointer" 
    35                                         }, 
    36                                         click: _displayClickHandler 
     32                        display: { 
     33                                style: { 
     34                                        cursor: "pointer" 
    3735                                }, 
    38                                 display_icon: { 
    39                                         style: { 
    40                                                 cursor: "pointer", 
    41                                                 position: "absolute", 
    42                                                 top: ((_api.skin.getSkinElement("display", "background").height - _api.skin.getSkinElement("display", "playIcon").height) / 2), 
    43                                                 left: ((_api.skin.getSkinElement("display", "background").width - _api.skin.getSkinElement("display", "playIcon").width) / 2), 
    44                                                 border: 0, 
    45                                                 margin: 0, 
    46                                                 padding: 0 
    47                                         } 
    48                                 }, 
    49                                 display_iconBackground: { 
    50                                         style: { 
    51                                                 cursor: "pointer", 
    52                                                 position: "absolute", 
    53                                                 top: ((_height - _api.skin.getSkinElement("display", "background").height) / 2), 
    54                                                 left: ((_width - _api.skin.getSkinElement("display", "background").width) / 2), 
    55                                                 border: 0, 
    56                                                 backgroundImage: (["url(", _api.skin.getSkinElement("display", "background").src, ")"]).join(""), 
    57                                                 width: _api.skin.getSkinElement("display", "background").width, 
    58                                                 height: _api.skin.getSkinElement("display", "background").height, 
    59                                                 margin: 0, 
    60                                                 padding: 0 
    61                                         } 
    62                                 }, 
    63                                 display_image: { 
    64                                         style: { 
    65                                                 display: "block", 
    66                                                 width: _width, 
    67                                                 height: _height, 
    68                                                 position: "absolute", 
    69                                                 cursor: "pointer", 
    70                                                 left: 0, 
    71                                                 top: 0, 
    72                                                 margin: 0, 
    73                                                 padding: 0, 
    74                                                 textDecoration: "none" 
    75                                         } 
    76                                 } 
    77                         }; 
     36                                click: _displayClickHandler 
     37                        }, 
     38                        display_icon: { 
     39                                style: { 
     40                                        cursor: "pointer", 
     41                                        position: "absolute", 
     42                                        top: ((_api.skin.getSkinElement("display", "background").height - _api.skin.getSkinElement("display", "playIcon").height) / 2), 
     43                                        left: ((_api.skin.getSkinElement("display", "background").width - _api.skin.getSkinElement("display", "playIcon").width) / 2), 
     44                                        border: 0, 
     45                                        margin: 0, 
     46                                        padding: 0 
     47                                } 
     48                        }, 
     49                        display_iconBackground: { 
     50                                style: { 
     51                                        cursor: "pointer", 
     52                                        position: "absolute", 
     53                                        top: ((_height - _api.skin.getSkinElement("display", "background").height) / 2), 
     54                                        left: ((_width - _api.skin.getSkinElement("display", "background").width) / 2), 
     55                                        border: 0, 
     56                                        backgroundImage: (["url(", _api.skin.getSkinElement("display", "background").src, ")"]).join(""), 
     57                                        width: _api.skin.getSkinElement("display", "background").width, 
     58                                        height: _api.skin.getSkinElement("display", "background").height, 
     59                                        margin: 0, 
     60                                        padding: 0 
     61                                } 
     62                        }, 
     63                        display_image: { 
     64                                style: { 
     65                                        display: "block", 
     66                                        width: _width, 
     67                                        height: _height, 
     68                                        position: "absolute", 
     69                                        cursor: "pointer", 
     70                                        left: 0, 
     71                                        top: 0, 
     72                                        margin: 0, 
     73                                        padding: 0, 
     74                                        textDecoration: "none" 
     75                                } 
     76                        }, 
     77                        display_text: { 
     78                                style: { 
     79                                        position: "relative", 
     80                                        top: "50%", 
     81                                        opacity: 0.8, 
     82                                        backgroundColor: "black", 
     83                                        color: "white", 
     84                                        display: "none", 
     85                                        textAlign: "center", 
     86                                        fontFamily: "Arial,sans-serif", 
     87                                        padding: "0 5px", 
     88                                        fontSize: 14 
     89                                } 
     90                        } 
     91                }; 
    7892                _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_PLAYER_STATE, _stateHandler); 
    7993                _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_MEDIA_MUTE, _stateHandler); 
    8094                _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_PLAYLIST_ITEM, _stateHandler); 
    81                 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_MEDIA_ERROR, function(obj) { 
    82                 }); 
     95                _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_ERROR, _errorHandler); 
    8396                _setupDisplay(); 
    84                  
    8597                 
    8698                function _setupDisplay() { 
    8799                        _display.display = createElement("div", "display"); 
     100                        _display.display_text = createElement("div", "display_text"); 
     101                        _display.display.appendChild(_display.display_text); 
    88102                        _display.display_image = createElement("div", "display_image"); 
    89103                        _display.display_icon = createElement("div", "display_icon"); 
     
    123137                        _css(_element, _elements[element].style); 
    124138                        return _element; 
    125                 } 
    126                  
    127                 function _getStyle(element) { 
    128                         var result = ''; 
    129                         for (var style in _elements[element].style) { 
    130                                 result += style + ":" + _elements[element].style[style] + ";"; 
    131                         } 
    132                         if (result === '') { 
    133                                 return ' '; 
    134                         } 
    135                         return ' style="' + result + '" '; 
    136139                } 
    137140                 
     
    190193                } 
    191194                 
    192                 function _stateHandler(obj) { 
     195                function _errorHandler(evt){ 
     196                        _hideDisplayIcon(); 
     197                        _display.display_text.innerHTML = "<p>"+evt.error+"</p>"; 
     198                        _show(_display.display_text); 
     199                        _display.display_text.style.top = ((_height -  _display.display_text.getBoundingClientRect().height) / 2) + "px"; 
     200                } 
     201                 
     202                function _stateHandler(evt) { 
     203                        _hide(_display.display_text); 
    193204                        if (_rotationInterval !== undefined) { 
    194205                                clearInterval(_rotationInterval); 
  • trunk/html5/src/html5/jwplayer.html5.mediavideo.js

    r1287 r1288  
    5858                var _start = false; 
    5959                var hasChrome = false; 
     60                var _currentItem; 
     61                var _sourceError = 0; 
    6062                 
    6163                function _getState() { 
     
    8385                                _model.state = newstate; 
    8486                                _state = newstate; 
     87                                var _sendComplete = false; 
    8588                                if (newstate == jwplayer.api.events.state.IDLE) { 
    8689                                        _clearInterval(); 
    87                                         _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE); 
     90                                        if (_model.position >= _model.duration && (_model.position || _model.duration)) { 
     91                                                _sendComplete = true; 
     92                                        } 
    8893                                         
    8994                                        if (_container.style.display != 'none') { 
     
    96101                                        newstate: newstate 
    97102                                }); 
     103                                if (_sendComplete) { 
     104                                        _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE); 
     105                                } 
    98106                        } 
    99107                        _stopped = false; 
     
    107115                                duration: event.target.duration 
    108116                        }; 
    109                         if (_model.duration === 0) { 
    110                                 _model.duration = event.target.duration; 
     117                        if (_model.duration === 0 || isNaN(_model.duration)) { 
     118                                _model.duration = Math.round(event.target.duration * 10) / 10; 
    111119                        } 
    112120                        _model.playlist[_model.item] = jwplayer.utils.extend(_model.playlist[_model.item], meta); 
     
    123131                         
    124132                        if (event !== undefined && event.target !== undefined) { 
    125                                 if (_model.duration === 0) { 
    126                                         _model.duration = event.target.duration; 
     133                                if (_model.duration === 0 || isNaN(_model.duration)) { 
     134                                        _model.duration = Math.round(event.target.duration * 10) / 10 
    127135                                } 
    128136                                if (!_start && _container.readyState > 0) { 
     
    160168                        } 
    161169                         
    162                         if (_bufferFull === false) { 
     170                        if (_bufferFull === false && _state == jwplayer.api.events.state.BUFFERING) { 
    163171                                _bufferFull = true; 
    164172                                _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER_FULL); 
     
    195203                 
    196204                function _errorHandler(event) { 
    197                         _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_ERROR, event.target); 
     205                        _stop(); 
     206                        var message = "There was an error: "; 
     207                        if (event.target.error || event.target.parentNode.error) { 
     208                                var element = event.target.error === undefined ? event.target.parentNode.error : event.target.error; 
     209                                switch (element.code) { 
     210                                        case element.MEDIA_ERR_ABORTED: 
     211                                                message = "You aborted the video playback: "; 
     212                                                break; 
     213                                        case element.MEDIA_ERR_NETWORK: 
     214                                                message = "A network error caused the video download to fail part-way: "; 
     215                                                break; 
     216                                        case element.MEDIA_ERR_DECODE: 
     217                                                message = "The video playback was aborted due to a corruption problem or because the video used features your browser did not support: "; 
     218                                                break; 
     219                                        case element.MEDIA_ERR_SRC_NOT_SUPPORTED: 
     220                                                message = "The video could not be loaded, either because the server or network failed or because the format is not supported: "; 
     221                                                break; 
     222                                        default: 
     223                                                message = "An unknown error occurred: "; 
     224                                                break; 
     225                                } 
     226                        } else if (event.target.tagName.toLowerCase() == "source") { 
     227                                _sourceError++; 
     228                                if (_sourceError != _currentItem.levels.length) { 
     229                                        return; 
     230                                } 
     231                                message = "The video could not be loaded, either because the server or network failed or because the format is not supported: "; 
     232                        } 
     233                         
     234                        message += joinFiles(); 
     235                        _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_ERROR, { 
     236                                error: message 
     237                        }); 
     238                        return; 
     239                } 
     240                 
     241                function joinFiles() { 
     242                        var result = ""; 
     243                        for (var sourceIndex in _currentItem.levels) { 
     244                                var sourceModel = _currentItem.levels[sourceIndex]; 
     245                                var source = _container.ownerDocument.createElement("source"); 
     246                                result += jwplayer.html5.utils.getAbsolutePath(sourceModel.file); 
     247                                if (sourceIndex < (_currentItem.levels.length - 1)) { 
     248                                        result += ", "; 
     249                                } 
     250                        } 
     251                        return result; 
    198252                } 
    199253                 
     
    228282                 
    229283                /** Stop playback and loading of the video. **/ 
    230                 this.stop = function() { 
     284                function _stop() { 
    231285                        _stopped = true; 
    232286                        _container.pause(); 
     
    234288                        _model.position = 0; 
    235289                        _setState(jwplayer.api.events.state.IDLE); 
    236                 }; 
    237                  
     290                } 
     291                 
     292                this.stop = _stop; 
    238293                 
    239294                /** Change the video's volume level. **/ 
     
    286341                this.load = function(playlistItem) { 
    287342                        _embed(playlistItem); 
    288                          
     343                        _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_LOADED); 
    289344                        _bufferFull = false; 
    290345                        _bufferingComplete = false; 
    291346                        _start = false; 
     347                        _setState(jwplayer.api.events.state.BUFFERING); 
     348                         
    292349                        setTimeout(function() { 
    293                                 _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_LOADED); 
    294                                 _setState(jwplayer.api.events.state.BUFFERING); 
    295350                                _positionHandler(); 
    296351                        }, 25); 
     
    298353                 
    299354                _embed = function(playlistItem) { 
     355                        _currentItem = playlistItem; 
    300356                        var vid = document.createElement("video"); 
    301357                        vid.preload = "none"; 
    302358                        vid.loop = _model.config.repeat; 
     359                        _sourceError = 0; 
    303360                        for (var sourceIndex in playlistItem.levels) { 
    304361                                var sourceModel = playlistItem.levels[sourceIndex]; 
Note: See TracChangeset for help on using the changeset viewer.