Changeset 926


Ignore:
Timestamp:
04/09/10 13:38:07 (3 years ago)
Author:
zach
Message:
  • Updating parsers
  • Adding intelligent Flash failover
Location:
trunk/html5/src
Files:
4 deleted
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/html5/src/jquery.jwplayerCore.js

    r925 r926  
    1414        return this.each(function() { 
    1515                $(this).css("display","none"); 
    16                 var domConfig = $.fn.jwplayerUtilsParsersDOMElementParser.parse(this); 
    17                 var model = $.extend(true, {}, $.fn.jwplayer.defaults, options, domConfig); 
    18                 $(this).data("model", model); 
     16                $(this).jwplayerParse(options); 
    1917                $(this).wrap("<div />"); 
    20                 $(this).before("<img src='" + model.image + "' style='width:" + model.width + "px,height:" + model.height + "px' />"); 
     18                $(this).before("<img src='" + $(this).data("model").image + "' style='width:" + $(this).data("model").width + "px,height:" + $(this).data("model").height + "px' />"); 
    2119                $(this).prev("img").click($.fn.jwplayer.play); 
    2220                // loadSkin(options); 
    2321        }); 
    24 } 
     22}; 
     23 
    2524 
    2625$.fn.jwplayer.play = function(event) { 
     
    3029                var source = model.sources[sourceIndex]; 
    3130                if (source.type == undefined) { 
    32                         source.type = 'video/' + source.file.substr(source.file.lastIndexOf('.')+1, source.file.length) + ';'; 
     31                        source.type = 'video/' + $.fn.jwplayerUtils.extension(source.file) + ';'; 
    3332                } 
    3433                if ($.fn.jwplayerUtils.supportsType(source.type)){ 
    35                         $(event.target).remove(); 
    36                         video.css("display","block"); 
     34                        model.item = sourceIndex; 
     35                        $(event.target).css("display","none"); 
     36                        video.css("display","inherit"); 
    3737                        video[0].play(); 
    3838                        model.state = 'playing'; 
    39                         break; 
    40                 } 
    41         }  
    42         if ($.fn.jwplayerUtils.supportsFlash && model.state != 'playing'){ 
    43                 if (event != undefined) { 
    44                         $.fn.jwplayerView.embedFlash(video, model); 
    45                         $(event.target).remove();                        
     39                        return true; 
    4640                } 
    4741        } 
    48 } 
     42        if ($.fn.jwplayerUtils.supportsFlash && model.state != 'playing'){ 
     43                for (var sourceIndex in model.sources) { 
     44                        var source = model.sources[sourceIndex]; 
     45                        $.fn.log($.fn.jwplayerUtils.flashCanPlay(source.file)); 
     46                        if ($.fn.jwplayerUtils.flashCanPlay(source.file)){ 
     47                                model.item = sourceIndex; 
     48                                $.fn.jwplayerView.embedFlash(video, model); 
     49                                $(event.target).css("display","none"); 
     50                                return true; 
     51                        } 
     52                }                        
     53        } 
     54        alert("No file to play!"); 
     55        return false; 
     56}; 
     57 
    4958 
    5059/** Map with all players on the page. **/ 
     
    6675        top:0, 
    6776        volume:100, 
    68         width:400 
     77        width:400, 
     78        item:0 
    6979}; 
    7080 
  • trunk/html5/src/jquery.jwplayerParse.js

    r920 r926  
    88(function($){ 
    99 
    10 $.fn.jwplayerUtilsParsers = function(){ 
     10var elementAttributes = { 
     11        'element':{ 
     12                'width':'width', 
     13                'height': 'height', 
     14                'id': 'id', 
     15                'class': 'className', 
     16                'name': 'name' 
     17        }, 
     18        'media': { 
     19                'src': 'file', 
     20                'preload': 'preload',  
     21                'autoplay': 'autostart', 
     22                'loop': 'repeat', 
     23                'controls': 'controls' 
     24        }, 
     25        'source':{ 
     26                'src': 'file', 
     27                'type': 'type', 
     28                'media': 'media' 
     29        }, 
     30        'video': { 
     31                'poster': 'image' 
     32        } 
    1133}; 
    1234 
     35var parsers = { 
     36} 
     37 
     38$.fn.jwplayerParse = function(options){ 
     39        return this.each(function() { 
     40                $(this).data("model", $.extend(true, {}, $.fn.jwplayer.defaults, options, parseElement(this))); 
     41        }); 
     42}; 
     43 
     44function getAttributeList(attributes, elementType) { 
     45        if  (attributes == undefined) { 
     46                attributes = elementAttributes[elementType]; 
     47        } else { 
     48                $.extend(attributes, elementAttributes[elementType]); 
     49        } 
     50        return attributes; 
     51} 
     52 
     53function parseElement(domElement, attributes) { 
     54        if (parsers[domElement.tagName.toLowerCase()] && (attributes == null)) { 
     55                return parsers[domElement.tagName.toLowerCase()](domElement); 
     56        } else { 
     57                attributes = getAttributeList(attributes, 'element'); 
     58                var configuration = {};                  
     59                for (var attribute in attributes) { 
     60                        if (attribute != "length") { 
     61                                var value = $(domElement).attr(attribute); 
     62                                if (!(value == "" || value == undefined)) { 
     63                                        configuration[attributes[attribute]] = $(domElement).attr(attribute); 
     64                                } 
     65                        } 
     66                } 
     67                return configuration; 
     68        } 
     69}; 
     70 
     71function parseMediaElement(domElement, attributes) { 
     72        attributes = getAttributeList(attributes, 'media'); 
     73        var sources = []; 
     74        $("source",domElement).each(function() { 
     75                sources[sources.length] = parseSourceElement(this); 
     76        }); 
     77        var configuration = parseElement(domElement, attributes); 
     78        if (configuration['file'] != undefined) { 
     79                sources[0] = {'file':configuration['file']}; 
     80        } 
     81        configuration['sources'] = sources; 
     82        return configuration; 
     83}; 
     84 
     85function parseSourceElement(domElement, attributes) { 
     86        attributes = getAttributeList(attributes, 'source'); 
     87        return parseElement(domElement, attributes); 
     88}; 
     89 
     90function parseVideoElement(domElement, attributes) { 
     91        attributes = getAttributeList(attributes, 'video'); 
     92        return parseMediaElement(domElement, attributes); 
     93} 
     94 
     95parsers['media'] = parseMediaElement; 
     96parsers['audio'] = parseMediaElement; 
     97parsers['source'] = parseSourceElement; 
     98parsers['video'] = parseVideoElement; 
     99 
     100 
    13101})(jQuery); 
  • trunk/html5/src/jquery.jwplayerUtils.js

    r924 r926  
    99(function($){ 
    1010 
     11/** Constructor **/ 
    1112$.fn.jwplayerUtils = function(){ 
    1213        return this.each(function() { 
    1314        }); 
    14 } 
     15}; 
    1516 
    1617/** Check if this client supports Flash player 9.0.115+ (FLV/H264). **/ 
     
    4142}; 
    4243 
    43 /** check if this client supports playback for the specified type. **/ 
     44/** Filetypes supported by Flash **/ 
     45var flashFileTypes = { 
     46        '3g2':true, 
     47        '3gp':true, 
     48        'aac':true, 
     49        'f4b':true, 
     50        'f4p':true, 
     51        'f4v':true, 
     52        'flv':true, 
     53        'gif':true, 
     54        'jpg':true, 
     55        'jpeg':true, 
     56        'm4a':true, 
     57        'm4v':true, 
     58        'mov':true, 
     59        'mp3':true, 
     60        'mp4':true, 
     61        'png':true, 
     62        'rbs':true, 
     63        'sdp':true, 
     64        'swf':true, 
     65        'vp6':true 
     66}; 
     67 
     68 
     69/** Check if this client supports Flash player 9.0.115+ (FLV/H264). **/ 
     70$.fn.jwplayerUtils.flashCanPlay = function(fileName) { 
     71        if (flashFileTypes[$.fn.jwplayerUtils.extension(fileName)]){ 
     72                return true; 
     73        }  
     74        return false; 
     75}; 
     76 
     77/** Check if this client supports playback for the specified type. **/ 
    4478$.fn.jwplayerUtils.supportsType = function(type) { 
    4579        try {  
     
    5084}; 
    5185 
    52 /** check if this client supports HTML5 H.264 playback. **/ 
     86/** Check if this client supports HTML5 H.264 playback. **/ 
    5387$.fn.jwplayerUtils.supportsH264 = function() { 
    5488        return $.fn.jwplayerUtils.supportsType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"'); 
     
    5690 
    5791 
    58 /** check if this client supports HTML5 OGG playback. **/ 
     92/** Check if this client supports HTML5 OGG playback. **/ 
    5993$.fn.jwplayerUtils.supportsOgg = function() { 
    6094        return $.fn.jwplayerUtils.supportsType('video/ogg; codecs="theora, vorbis"'); 
    6195}; 
    6296 
     97/** Returns the extension of a file name **/ 
     98$.fn.jwplayerUtils.extension = function(path) { 
     99        return path.substr(path.lastIndexOf('.')+1, path.length); 
     100}; 
     101 
     102/** Dumps the content of an object to a string **/ 
    63103$.fn.jwplayerUtils.dump = function(object, depth) { 
    64104        if (object == null) { 
     
    92132        return result; 
    93133}; 
    94          
     134 
     135/** Returns the true type of an object **/       
    95136$.fn.jwplayerUtils.typeOf = function(value) { 
    96137        var s = typeof value; 
     
    108149 
    109150 
     151/** Logger **/ 
    110152$.fn.log = function (msg, obj) { 
    111153        try { 
    112                 console.log("%s: %o", msg, obj); 
     154                if (obj) { 
     155                        console.log("%s: %o", msg, obj); 
     156                } else { 
     157                        console.log($.fn.jwplayerUtils.dump(msg)); 
     158                } 
    113159        } catch (err) { 
    114160        } 
  • trunk/html5/src/jquery.jwplayerView.js

    r923 r926  
    2323                        "allowfullscreen='true' " +  
    2424                        "allowscriptaccess='always' " +  
    25                         "flashvars='file=" + model.sources[0].file + "&image=" + model.image + "' " +  
     25                        "flashvars='file=" + model.sources[model.item].file + "&image=" + model.image + "' " +  
    2626                        "/>" 
    2727                ); 
     
    3232                        "<param name='allowscriptaccess' value='always'>" +  
    3333                        "<param name='wmode' value='transparent'>" +  
    34                         "<param name='flashvars' value='file=" + model.sources[0].file + "&image=" + model.image + "'>" +  
     34                        "<param name='flashvars' value='file=" + model.sources[model.item].file + "&image=" + model.image + "'>" +  
    3535                        "</object>" 
    3636                ); 
Note: See TracChangeset for help on using the changeset viewer.