Changeset 1194


Ignore:
Timestamp:
08/02/10 11:49:36 (3 years ago)
Author:
pablo
Message:

Adding playerReady callback to API

Location:
trunk/js
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/js/bin-debug/embed.html

    r1183 r1194  
    11<html> 
    22        <head> 
     3                <script type="text/javascript" src="jquery.js"></script> 
     4                <script type="text/javascript" src="jquery.jwplayerParse.js"></script> 
    35                <script type="text/javascript" src="jwplayer.js"></script> 
     6                <script type="text/javascript" src="jwplayer.html5.js"></script> 
    47                <script type="text/javascript"> 
    58                        var options = { 
    69                                file:           '../../../testing/files/bunny.mp4', 
    710                                image:          '../../../testing/files/bunny.jpg', 
    8                                  
    9                                 players: [{type:'flash', src: '../../../trunk/fl5/player.swf'}] 
     11                        sources: [{ 
     12                            file:"http://content.bitsontherun.com/videos/nPripu9l-327.mp4", 
     13                            type: "video/mp4" 
     14                        }],                               
     15                                plugins:        { 
     16                                        'sharing-1': {}, 
     17                                        'viral-2d': { 
     18                                                link: 'http://www.longtailvideo.com', 
     19                                                'viral.allowmenu': 'true' 
     20                                        }, 
     21                                        'fbit-1': {} 
     22                                }, 
     23                                players: [ 
     24                                        {type:'flash', src: '../../../trunk/fl5/player.swf'}, 
     25                                        {type:'html5'}, 
     26                                ] 
    1027                        };  
    11                         function embedPlayer() { 
    12                                 return $jw('div1').setup(options); 
     28                        function embedPlayer(id) { 
     29                                return $jw(id).setup(options); 
    1330                        }        
    1431                </script> 
     
    1734        <body> 
    1835                <h1>JWPlayer JS Embedder Testing Page</h1> 
    19                 <div id="div1"> 
    20                         This is &lt;div&gt; 1. 
     36                <div id="something"> 
     37                        <video id="div1" src="../test/files/bunny.ogv"> 
     38                                This is &lt;div&gt; 1. 
     39                        </video> 
     40                </div> 
     41                <div id="something_else"> 
     42                        <div id="div2"> 
     43                                This is &lt;div&gt; 2 
     44                        </div> 
    2145                </div> 
    2246                <script type="text/javascript"> 
    23                         embedPlayer(); 
     47                        embedPlayer('div1'); 
    2448                </script> 
    25  
    2649                <h3>Embed a player</h3> 
    27                 <a href="#" onclick="embedPlayer(); return false;">Click here to embed player</a><br /> 
     50                <a href="#" onclick="embedPlayer('div2'); return false;">Click here to embed player</a><br /> 
    2851 
    2952        </body> 
  • trunk/js/bin-debug/jwplayer.js

    r1183 r1194  
    8888        return inputString.replace(/^\s*/, "").replace(/\s*$/, ""); 
    8989}; 
    90 jwplayer.constuctor = function(container) { 
    91         return jwplayer.api.selectPlayer(container); 
    92 }; 
    93  
    94 jwplayer.api = function() {}; 
    95  
    96 jwplayer.api._players = []; 
    97  
    98 jwplayer.api.PlayerAPI = function(container) { 
    99         this.container = container; 
    100         this.id = container.id; 
    101 }; 
    102  
    103 jwplayer.api.PlayerAPI.prototype = { 
    104         // Player properties 
    105         container: undefined, 
    106         player: undefined, 
    107         options: undefined, 
    108         id: undefined, 
    109         callbacks: {}, 
    110          
    111         // Player Getters 
    112         getBuffer: function() { return undefined; }, 
    113         getFullscreen: function() { return undefined; }, 
    114         getLockState: function() { return undefined; }, 
    115         getMeta: function() { return undefined; }, 
    116         getMute: function() { return undefined; }, 
    117         getPlaylist: function() { return undefined; }, 
    118         getPlaylistItem: function() { return undefined; }, 
    119         getHeight: function() { return undefined; }, 
    120         getWidth: function() { return undefined; }, 
    121         getState: function() { return undefined; }, 
    122         getPosition: function() { return undefined; }, 
    123         getDuration: function() { return undefined; }, 
    124         getVolume: function() { return undefined; }, 
    125          
    126         // Player Public Methods 
    127         setFullscreen: function() { return this; }, 
    128         setMute: function() { return this; }, 
    129         lock: function() { return this; }, 
    130         unlock: function() { return this; }, 
    131         load: function() { return this; }, 
    132         playlistItem: function() { return this; }, 
    133         playlistPrev: function() { return this; }, 
    134         playlistNext: function() { return this; }, 
    135         resize: function() { return this; }, 
    136         play: function() { return this; }, 
    137         pause: function() { return this; }, 
    138         stop: function() { return this; }, 
    139         seek: function() { return this; }, 
    140         setVolume: function() { return this; }, 
    141          
    142         // Player Events 
    143         onBuffer: function() { return this; }, 
    144         onBufferFull: function() { return this; }, 
    145         onError: function() { return this; }, 
    146         onFullscreen: function() { return this; }, 
    147         onMeta: function() { return this; }, 
    148         onMute: function() { return this; }, 
    149         onPlaylist: function() { return this; }, 
    150         onPlaylistItem: function() { return this; }, 
    151         onReady: function() { return this; }, 
    152         onResize: function() { return this; }, 
    153         onState: function() { return this; }, 
    154         onComplete: function() { return this; }, 
    155         onTime: function() { return this; }, 
    156         onVolume: function() { return this; }, 
    157  
    158         // Player plugin API 
    159         initializePlugin: function(pluginName, pluginCode) { return this; } 
    160 }; 
    161  
    162 jwplayer.api.selectPlayer = function(identifier) { 
    163         var _container; 
    164          
    165         if (identifier == undefined) identifier = 0; 
    166          
    167         if (identifier.nodeType) { 
    168                 // Handle DOM Element 
    169                 _container = identifier; 
    170         } else if (typeof identifier == 'string') { 
    171                 // Find container by ID 
    172                 _container = document.getElementById(identifier); 
    173         } 
    174          
    175         if (_container) {   
    176                 var foundPlayer = jwplayer.api.playerByContainer(_container); 
    177                 if (foundPlayer) { 
    178                         return foundPlayer;  
     90(function(jwplayer) { 
     91        var _players = []; 
     92 
     93        jwplayer.constuctor = function(container) { 
     94                return jwplayer.api.selectPlayer(container); 
     95        }; 
     96         
     97        jwplayer.api = function() {}; 
     98 
     99        jwplayer.api.events = { 
     100                JWPLAYER_READY: 'jwplayerReady', 
     101                JWPLAYER_FULLSCREEN: 'jwplayerFullscreen', 
     102                JWPLAYER_RESIZE: 'jwplayerResize', 
     103                JWPLAYER_ERROR: 'jwplayerError', 
     104                JWPLAYER_MEDIA_BUFFER: 'jwplayerMediaBuffer', 
     105                JWPLAYER_MEDIA_BUFFER_FULL: 'jwplayerMediaBufferFull', 
     106                JWPLAYER_MEDIA_ERROR: 'jwplayerMediaError', 
     107                JWPLAYER_MEDIA_LOADED: 'jwplayerMediaLoaded', 
     108                JWPLAYER_MEDIA_COMPLETE: 'jwplayerMediaComplete', 
     109                JWPLAYER_MEDIA_TIME: 'jwplayerMediaTime', 
     110                JWPLAYER_MEDIA_VOLUME: 'jwplayerMediaVolume', 
     111                JWPLAYER_MEDIA_META: 'jwplayerMediaMeta', 
     112                JWPLAYER_MEDIA_MUTE: 'jwplayerMediaMute', 
     113                JWPLAYER_PLAYER_STATE: 'jwplayerPlayerState', 
     114                JWPLAYER_PLAYLIST_LOADED: 'jwplayerPlaylistLoaded', 
     115                JWPLAYER_PLAYLIST_ITEM: 'jwplayerPlaylistItem' 
     116        }; 
     117         
     118        jwplayer.api.events.state = { 
     119                BUFFERING: 'BUFFERING', 
     120                IDLE: 'IDLE', 
     121                PAUSED: 'PAUSED', 
     122                PLAYING: 'PLAYING' 
     123        }; 
     124         
     125        jwplayer.api.PlayerAPI = function(container) { 
     126                var _listeners = {}; 
     127                var _stateListeners = {}; 
     128                var _player = undefined; 
     129                 
     130                this.container = container; 
     131                this.id = container.id; 
     132                 
     133                this.stateListener = function(state, callback) { 
     134                        if (!_stateListeners[state]) {  
     135                                _stateListeners[state] = [];  
     136                                this.eventListener(jwplayer.api.events.JWPLAYER_PLAYER_STATE, this.stateCallback(state)); 
     137                        }  
     138                        _stateListeners[state].push(callback); 
     139                        return this; 
     140                }; 
     141                 
     142                this.stateCallback = function(state) { 
     143                        return function(newstate, oldstate) { 
     144                                if (newstate == state) { 
     145                                        var callbacks = _stateListeners[newstate]; 
     146                                        if (callbacks) { 
     147                                                for (var c in callbacks) { 
     148                                                        if (typeof callbacks[c] == 'function') { 
     149                                                                callbacks[c].call(this, oldstate); 
     150                                                        } 
     151                                                } 
     152                                        } 
     153                                } 
     154                        }; 
     155                }; 
     156                 
     157                this.eventListener = function(type, callback) { 
     158                        if (!_listeners[type]) { _listeners[type] = []; } 
     159                        _listeners[type].push(callback); 
     160                        return this; 
     161                }; 
     162                 
     163                this.dispatchEvent = function(type) { 
     164                        if (_listeners[type]) { 
     165                                for (var l in _listeners[type]) { 
     166                                        if (typeof _listeners[type][l] == 'function') { 
     167                                                _listeners[type][l].apply(this, slice(arguments, 1)); 
     168                                        } 
     169                                } 
     170                        } 
     171                }; 
     172                 
     173                this.playerReady = function() { 
     174                        _player = this.container; 
     175                }; 
     176                 
     177                /** Using this function instead of array.slice since Arguments are not an array **/ 
     178                function slice(list, from, to) { 
     179                        var ret = []; 
     180                        if (!from) { from = 0; } 
     181                        if (!to) { to = list.length-1; } 
     182                        for (var i=from; i<=to; i++) { 
     183                                ret.push(list[i]); 
     184                        } 
     185                        return ret; 
     186                } 
     187        }; 
     188 
     189        jwplayer.api.PlayerAPI.prototype = { 
     190                // Player properties 
     191                container: undefined, 
     192                options: undefined, 
     193                id: undefined, 
     194                 
     195                // Player Getters 
     196                getBuffer: function() { return undefined; }, 
     197                getFullscreen: function() { return undefined; }, 
     198                getLockState: function() { return undefined; }, 
     199                getMeta: function() { return undefined; }, 
     200                getMute: function() { return undefined; }, 
     201                getPlaylist: function() { return undefined; }, 
     202                getPlaylistItem: function() { return undefined; }, 
     203                getHeight: function() { return undefined; }, 
     204                getWidth: function() { return undefined; }, 
     205                getState: function() { return undefined; }, 
     206                getPosition: function() { return undefined; }, 
     207                getDuration: function() { return undefined; }, 
     208                getVolume: function() { return undefined; }, 
     209                 
     210                // Player Public Methods 
     211                setFullscreen: function() { return this; }, 
     212                setMute: function() { return this; }, 
     213                lock: function() { return this; }, 
     214                unlock: function() { return this; }, 
     215                load: function() { return this; }, 
     216                playlistItem: function() { return this; }, 
     217                playlistPrev: function() { return this; }, 
     218                playlistNext: function() { return this; }, 
     219                resize: function() { return this; }, 
     220                play: function() {  
     221                        this.dispatchEvent(jwplayer.api.events.JWPLAYER_PLAYER_STATE, 'BUFFERING', 'IDLE');  
     222                        this.dispatchEvent(jwplayer.api.events.JWPLAYER_PLAYER_STATE, 'PLAYING', 'BUFFERING');  
     223                        return this;  
     224                }, 
     225                pause: function() {  
     226                        this.dispatchEvent(jwplayer.api.events.JWPLAYER_PLAYER_STATE, 'PAUSED', 'PLAYING');  
     227                        return this;  
     228                }, 
     229                stop: function() {  
     230                        this.dispatchEvent(jwplayer.api.events.JWPLAYER_PLAYER_STATE, 'IDLE', 'PLAYING');  
     231                        return this;  
     232                }, 
     233                seek: function() { return this; }, 
     234                setVolume: function() { return this; }, 
     235                 
     236                // Player Events 
     237                onBufferProgress: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER, callback); }, 
     238                onBufferFull: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER_FULL, callback); }, 
     239                onError: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_ERROR, callback); }, 
     240                onFullscreen: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_FULLSCREEN, callback); }, 
     241                onMeta: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_META, callback); }, 
     242                onMute: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_MUTE, callback); }, 
     243                onPlaylist: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_PLAYLIST_LOADED, callback); }, 
     244                onPlaylistItem: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_PLAYLIST_ITEM, callback); }, 
     245                onReady: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_READY, callback); }, 
     246                onResize: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_RESIZE, callback); }, 
     247                onComplete: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE, callback); }, 
     248                onTime: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_TIME, callback); }, 
     249                onVolume: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_VOLUME, callback); }, 
     250         
     251                // State events 
     252                onBuffer: function(callback) { return this.stateListener(jwplayer.api.events.state.BUFFERING, callback); }, 
     253                onPause: function(callback) { return this.stateListener(jwplayer.api.events.state.PAUSED, callback); }, 
     254                onPlay: function(callback) { return this.stateListener(jwplayer.api.events.state.PLAYING, callback); }, 
     255                onStop: function(callback) { return this.stateListener(jwplayer.api.events.state.IDLE, callback); }, 
     256 
     257                // Player plugin API 
     258                initializePlugin: function(pluginName, pluginCode) { return this; }, 
     259        }; 
     260         
     261        jwplayer.api.selectPlayer = function(identifier) { 
     262                var _container; 
     263                 
     264                if (identifier == undefined) identifier = 0; 
     265                 
     266                if (identifier.nodeType) { 
     267                        // Handle DOM Element 
     268                        _container = identifier; 
     269                } else if (typeof identifier == 'string') { 
     270                        // Find container by ID 
     271                        _container = document.getElementById(identifier); 
     272                } 
     273                 
     274                if (_container) {   
     275                        var foundPlayer = jwplayer.api.playerByContainer(_container); 
     276                        if (foundPlayer) { 
     277                                return foundPlayer;  
     278                        } else { 
     279                                // Todo: register new object 
     280                                return new jwplayer.api.PlayerAPI(_container);  
     281                        } 
     282                } else if (typeof identifier == 'number') { 
     283                        return jwplayer.getPlayers()[identifier]; 
     284                } 
     285         
     286                return null; 
     287        }; 
     288         
     289        jwplayer.api.playerByContainer = function(cont) { 
     290                for(var p in _players) { 
     291                        if (_players[p].container == cont) { 
     292                                return _players[p]; 
     293                        } 
     294                } 
     295                return null; 
     296        }; 
     297         
     298        jwplayer.register = jwplayer.api.addPlayer = function(player) { 
     299                for (var i in _players) { 
     300                        if (_players[i] == player) { 
     301                                return player; // Player is already in the list; 
     302                        } 
     303                } 
     304         
     305                _players.push(player); 
     306                return player; 
     307        }; 
     308         
     309        // Can't make this a read-only getter, thanks to IE incompatibility. 
     310        jwplayer.getPlayers = function() {  
     311                return _players.slice(0);  
     312        }; 
     313         
     314        var _userPlayerReady = (typeof playerReady == 'function') ? playerReady : undefined; 
     315         
     316        playerReady = function(obj) { 
     317                var api = jwplayer(obj['id']); 
     318                api.playerReady(); 
     319                 
     320                // Todo: setup event callbacks 
     321                // Todo: run any queued up commands  
     322                 
     323                if (_userPlayerReady) { 
     324                        _userPlayerReady.call(this, obj); 
     325                }                
     326        }; 
     327         
     328})(jwplayer);(function(jwplayer) { 
     329 
     330        jwplayer.embed = function() {}; 
     331         
     332        jwplayer.embed.Embedder = function(playerApi) { 
     333                var events = {}, 
     334                        players = {}, 
     335                        config = undefined, 
     336                        api = undefined; 
     337                 
     338                this.constructor(playerApi); 
     339        }; 
     340         
     341        jwplayer.embed.Embedder.prototype = { 
     342                constructor: function(playerApi) { 
     343                        this.api = playerApi; 
     344                        this.config = this.parseConfig(this.api.config); 
     345                }, 
     346         
     347                embedPlayer: function() { 
     348                        var player = this.players[0]; 
     349                        if (player && player.type) { 
     350                                switch (player.type) { 
     351                                case 'flash': 
     352                                        this.api.container = jwplayer.embed.embedFlash(this.api.container, player, this.config); 
     353                                        break; 
     354                                case 'html5': 
     355                                        this.api.player = jwplayer.embed.embedHTML5(this.api.container, player, this.config); 
     356                                        playerReady({id:this.api.container.id}); 
     357                                        break; 
     358                                } 
     359                        } 
     360                        return jwplayer.register(this.api); 
     361                }, 
     362                 
     363                parseConfig: function(config) { 
     364                        var parsedConfig = jwplayer.utils.extend({}, config); 
     365                        if(parsedConfig.events) { 
     366                                this.events = parsedConfig.events; 
     367                                delete parsedConfig['events']; 
     368                        } 
     369                        if(parsedConfig.players) { 
     370                                this.players = parsedConfig.players; 
     371                                delete parsedConfig['players']; 
     372                        } 
     373                        if(parsedConfig.plugins) { 
     374                                if (typeof parsedConfig.plugins == "object") { 
     375                                        parsedConfig = jwplayer.utils.extend(parsedConfig, jwplayer.embed.parsePlugins(parsedConfig.plugins)); 
     376                                } 
     377                        } 
     378                        return parsedConfig; 
     379                } 
     380         
     381        }; 
     382         
     383        jwplayer.embed.defaults = { 
     384                width: 400, 
     385                height: 300 
     386        }; 
     387         
     388        jwplayer.embed.embedFlash = function(container, player, options) { 
     389                var params = jwplayer.utils.extend({}, jwplayer.embed.defaults, options); 
     390                 
     391                var width = params.width;  
     392                delete params['width']; 
     393                 
     394                var height = params.height;  
     395                delete params['height']; 
     396                 
     397                if (jwplayer.utils.isIE()) { 
     398                        var html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +  
     399                                'width="' + width + '" height="' + height + '" ' + 
     400                                'id="' + container.id + '" name="' + container.id + 
     401                                '">'; 
     402                        html += '<param name="movie" value="' + player.src + '">'; 
     403                        html += '<param name="allowfullscreen" value="true">'; 
     404                        html += '<param name="allowscriptaccess" value="always">'; 
     405                        html += '<param name="flashvars" value="' + jwplayer.embed.jsonToFlashvars(params) +'">'; 
     406                        html += '</object>'; 
     407                        container.outerHTML = html; 
     408                        return container; 
    179409                } else { 
    180                         // Todo: register new object 
    181                         return jwplayer.api.addPlayer(new jwplayer.api.PlayerAPI(_container));  
    182                 } 
    183         } else if (typeof identifier == 'number') { 
    184                 return jwplayer.players[identifier]; 
    185         } 
    186  
    187         return null; 
    188 }; 
    189  
    190 jwplayer.api.playerByContainer = function(cont) { 
    191         for(var p in jwplayer.players) { 
    192                 if (jwplayer.players[p].container == cont) { 
    193                         return jwplayer.players[p]; 
    194                 } 
    195         } 
    196         return null; 
    197 }; 
    198  
    199 jwplayer.api.addPlayer = function(player) { 
    200         for (var i in jwplayer.players) { 
    201                 if (jwplayer.players[i] == player) { 
    202                         return player; // Player is already in the list; 
    203                 } 
    204         } 
    205  
    206         jwplayer.api._players.push(player); 
    207         return player; 
    208 }; 
    209  
    210 // Can't make this a read-only getter, thanks to IE incompatibility. 
    211 jwplayer.players = jwplayer.api._players; 
    212  
    213 var _userPlayerReady = playerReady; 
    214  
    215 function playerReady(obj) { 
    216         var cont = jwplayer(obj['id']); 
    217         var api = jwplayer.api.playerByContainer(cont); 
    218         api.player = cont; 
    219         // Todo: setup event callbacks 
    220         // Todo: run any queued up commands  
    221          
    222         if (_userPlayerReady && _userPlayerReady.call) { 
    223                 _userPlayerReady.call(this, obj); 
    224         }                
    225 }jwplayer.embed = function() {}; 
    226  
    227 jwplayer.embed.Embedder = function(playerApi) { 
    228         this.constructor(playerApi); 
    229 }; 
    230  
    231 jwplayer.embed.Embedder.prototype = { 
    232         api: undefined, 
    233         config: undefined, 
    234         events: {}, 
    235         players: {}, 
    236  
    237         constructor: function(playerApi) { 
    238                 this.api = playerApi; 
    239                 this.config = this.parseConfig(this.api.config); 
    240         }, 
    241  
    242         embedPlayer: function() { 
    243                 var player = this.players[0]; 
    244                 if (player && player.type) { 
    245                         switch (player.type) { 
    246                         case 'flash': 
    247                                 jwplayer.embed.embedFlash(this.api.container, player, this.config); 
    248                         } 
    249                 } 
    250                  
    251                 return this.api; 
    252         }, 
    253          
    254         parseConfig: function(config) { 
    255                 var parsedConfig = jwplayer.utils.extend({}, config); 
    256                 if(parsedConfig.events) { 
    257                         this.events = parsedConfig.events; 
    258                         delete parsedConfig['events']; 
    259                 } 
    260                 if(parsedConfig.players) { 
    261                         this.players = parsedConfig.players; 
    262                         delete parsedConfig['players']; 
    263                 } 
    264                 return parsedConfig; 
    265         } 
    266          
    267 }; 
    268  
    269 jwplayer.embed.defaults = { 
    270         width: 400, 
    271         height: 300 
    272 }; 
    273  
    274 jwplayer.embed.embedFlash = function(container, player, options) { 
    275         var params = jwplayer.utils.extend({}, jwplayer.embed.defaults, options); 
    276          
    277         var width = params.width;  
    278         delete params['width']; 
    279          
    280         var height = params.height;  
    281         delete params['height']; 
    282          
    283         if (jwplayer.utils.isIE()) { 
    284                 var html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +  
    285                         'width="' + width + '" height="' + height + '" ' + 
    286                         'id="' + container.id + '" name="' + container.id + 
    287                         '">'; 
    288                 html += '<param name="movie" value="' + player.src + '">'; 
    289                 html += '<param name="allowfullscreen" value="true">'; 
    290                 html += '<param name="allowscriptaccess" value="always">'; 
    291                 html += '<param name="flashvars" value="' + jwplayer.embed.jsonToFlashvars(params) +'">'; 
    292                 html += '</object>'; 
    293                 container.outerHTML = html; 
    294         } else { 
    295                 var obj = document.createElement('object'); 
    296                 obj.setAttribute('type', 'application/x-shockwave-flash'); 
    297                 obj.setAttribute('data', player.src); 
    298                 obj.setAttribute('width', width); 
    299                 obj.setAttribute('height', height); 
    300                 obj.setAttribute('id', container.id); 
    301                 obj.setAttribute('name', container.id); 
    302                 jwplayer.embed.appendAttribute(obj, 'allowfullscreen', 'true'); 
    303                 jwplayer.embed.appendAttribute(obj, 'allowscriptaccess', 'always'); 
    304                 jwplayer.embed.appendAttribute(obj, 'flashvars', jwplayer.embed.jsonToFlashvars(params)); 
    305                 container.parentNode.replaceChild(obj, container); 
    306         } 
    307 }; 
    308  
    309 jwplayer.embed.appendAttribute = function(object, name, value) { 
    310         var param = document.createElement('param'); 
    311         param.setAttribute('name', name); 
    312         param.setAttribute('value', value); 
    313         object.appendChild(param); 
    314 }; 
    315  
    316 jwplayer.embed.jsonToFlashvars = function(json) { 
    317         var flashvars = ''; 
    318         for (key in json) { 
    319                 flashvars += key + '=' + escape(json[key]) + '&'; 
    320         } 
    321         return flashvars.substring(0, flashvars.length-1); 
    322 }; 
    323  
    324 jwplayer.api.PlayerAPI.prototype.setup = function(options, player) { 
    325         this.config = options; 
    326         this.player = player; 
    327         return (new jwplayer.embed.Embedder(this)).embedPlayer(); 
    328 }; 
     410                        var obj = document.createElement('object'); 
     411                        obj.setAttribute('type', 'application/x-shockwave-flash'); 
     412                        obj.setAttribute('data', player.src); 
     413                        obj.setAttribute('width', width); 
     414                        obj.setAttribute('height', height); 
     415                        obj.setAttribute('id', container.id); 
     416                        obj.setAttribute('name', container.id); 
     417                        jwplayer.embed.appendAttribute(obj, 'allowfullscreen', 'true'); 
     418                        jwplayer.embed.appendAttribute(obj, 'allowscriptaccess', 'always'); 
     419                        jwplayer.embed.appendAttribute(obj, 'flashvars', jwplayer.embed.jsonToFlashvars(params)); 
     420                        container.parentNode.replaceChild(obj, container); 
     421                        return obj; 
     422                } 
     423        }; 
     424         
     425        jwplayer.embed.embedHTML5 = function(container, player, options) { 
     426                if (jwplayer.html5) { 
     427                        var player = new (jwplayer.html5(container)).setup(jwplayer.utils.extend({}, jwplayer.embed.defaults, options)); 
     428                        return player; 
     429                } else { 
     430                        return null; 
     431                } 
     432        }; 
     433         
     434        jwplayer.embed.appendAttribute = function(object, name, value) { 
     435                var param = document.createElement('param'); 
     436                param.setAttribute('name', name); 
     437                param.setAttribute('value', value); 
     438                object.appendChild(param); 
     439        }; 
     440         
     441        jwplayer.embed.jsonToFlashvars = function(json) { 
     442                var flashvars = ''; 
     443                for (key in json) { 
     444                        flashvars += key + '=' + escape(json[key]) + '&'; 
     445                } 
     446                return flashvars.substring(0, flashvars.length-1); 
     447        }; 
     448         
     449        jwplayer.embed.parsePlugins = function(pluginBlock) { 
     450                if (!pluginBlock) return {}; 
     451                 
     452                var flat = {}, 
     453                        pluginKeys = []; 
     454                 
     455                for (plugin in pluginBlock) { 
     456                        var pluginName = plugin.indexOf('-') > 0 ? plugin.substring(0, plugin.indexOf('-')) : plugin; 
     457                        var pluginConfig = pluginBlock[plugin]; 
     458                        pluginKeys.push(plugin); 
     459                        for (param in pluginConfig) { 
     460                                flat[pluginName+'.'+param] = pluginConfig[param]; 
     461                        } 
     462                } 
     463                flat['plugins'] = pluginKeys.join(',');  
     464                return flat; 
     465        }; 
     466         
     467        jwplayer.api.PlayerAPI.prototype.setup = function(options, player) { 
     468                this.config = options; 
     469                if(player) { this.player = player; } 
     470                jwplayer.register(this); 
     471                return (new jwplayer.embed.Embedder(this)).embedPlayer(); 
     472        }; 
     473         
     474})(jwplayer); 
  • trunk/js/src/api/jwplayer.api.js

    r1183 r1194  
    1 jwplayer.constuctor = function(container) { 
    2         return jwplayer.api.selectPlayer(container); 
    3 }; 
    4  
    5 jwplayer.api = function() {}; 
    6  
    7 jwplayer.api._players = []; 
    8  
    9 jwplayer.api.PlayerAPI = function(container) { 
    10         this.container = container; 
    11         this.id = container.id; 
    12 }; 
    13  
    14 jwplayer.api.PlayerAPI.prototype = { 
    15         // Player properties 
    16         container: undefined, 
    17         player: undefined, 
    18         options: undefined, 
    19         id: undefined, 
    20         callbacks: {}, 
    21          
    22         // Player Getters 
    23         getBuffer: function() { return undefined; }, 
    24         getFullscreen: function() { return undefined; }, 
    25         getLockState: function() { return undefined; }, 
    26         getMeta: function() { return undefined; }, 
    27         getMute: function() { return undefined; }, 
    28         getPlaylist: function() { return undefined; }, 
    29         getPlaylistItem: function() { return undefined; }, 
    30         getHeight: function() { return undefined; }, 
    31         getWidth: function() { return undefined; }, 
    32         getState: function() { return undefined; }, 
    33         getPosition: function() { return undefined; }, 
    34         getDuration: function() { return undefined; }, 
    35         getVolume: function() { return undefined; }, 
    36          
    37         // Player Public Methods 
    38         setFullscreen: function() { return this; }, 
    39         setMute: function() { return this; }, 
    40         lock: function() { return this; }, 
    41         unlock: function() { return this; }, 
    42         load: function() { return this; }, 
    43         playlistItem: function() { return this; }, 
    44         playlistPrev: function() { return this; }, 
    45         playlistNext: function() { return this; }, 
    46         resize: function() { return this; }, 
    47         play: function() { return this; }, 
    48         pause: function() { return this; }, 
    49         stop: function() { return this; }, 
    50         seek: function() { return this; }, 
    51         setVolume: function() { return this; }, 
    52          
    53         // Player Events 
    54         onBuffer: function() { return this; }, 
    55         onBufferFull: function() { return this; }, 
    56         onError: function() { return this; }, 
    57         onFullscreen: function() { return this; }, 
    58         onMeta: function() { return this; }, 
    59         onMute: function() { return this; }, 
    60         onPlaylist: function() { return this; }, 
    61         onPlaylistItem: function() { return this; }, 
    62         onReady: function() { return this; }, 
    63         onResize: function() { return this; }, 
    64         onState: function() { return this; }, 
    65         onComplete: function() { return this; }, 
    66         onTime: function() { return this; }, 
    67         onVolume: function() { return this; }, 
    68  
    69         // Player plugin API 
    70         initializePlugin: function(pluginName, pluginCode) { return this; } 
    71 }; 
    72  
    73 jwplayer.api.selectPlayer = function(identifier) { 
    74         var _container; 
    75          
    76         if (identifier == undefined) identifier = 0; 
    77          
    78         if (identifier.nodeType) { 
    79                 // Handle DOM Element 
    80                 _container = identifier; 
    81         } else if (typeof identifier == 'string') { 
    82                 // Find container by ID 
    83                 _container = document.getElementById(identifier); 
    84         } 
    85          
    86         if (_container) {   
    87                 var foundPlayer = jwplayer.api.playerByContainer(_container); 
    88                 if (foundPlayer) { 
    89                         return foundPlayer;  
    90                 } else { 
    91                         // Todo: register new object 
    92                         return jwplayer.api.addPlayer(new jwplayer.api.PlayerAPI(_container));  
    93                 } 
    94         } else if (typeof identifier == 'number') { 
    95                 return jwplayer.players[identifier]; 
    96         } 
    97  
    98         return null; 
    99 }; 
    100  
    101 jwplayer.api.playerByContainer = function(cont) { 
    102         for(var p in jwplayer.players) { 
    103                 if (jwplayer.players[p].container == cont) { 
    104                         return jwplayer.players[p]; 
    105                 } 
    106         } 
    107         return null; 
    108 }; 
    109  
    110 jwplayer.api.addPlayer = function(player) { 
    111         for (var i in jwplayer.players) { 
    112                 if (jwplayer.players[i] == player) { 
    113                         return player; // Player is already in the list; 
    114                 } 
    115         } 
    116  
    117         jwplayer.api._players.push(player); 
    118         return player; 
    119 }; 
    120  
    121 // Can't make this a read-only getter, thanks to IE incompatibility. 
    122 jwplayer.players = jwplayer.api._players; 
    123  
    124 var _userPlayerReady = playerReady; 
    125  
    126 function playerReady(obj) { 
    127         var cont = jwplayer(obj['id']); 
    128         var api = jwplayer.api.playerByContainer(cont); 
    129         api.player = cont; 
    130         // Todo: setup event callbacks 
    131         // Todo: run any queued up commands  
    132          
    133         if (_userPlayerReady && _userPlayerReady.call) { 
    134                 _userPlayerReady.call(this, obj); 
    135         }                
    136 } 
     1(function(jwplayer) { 
     2        var _players = []; 
     3 
     4        jwplayer.constuctor = function(container) { 
     5                return jwplayer.api.selectPlayer(container); 
     6        }; 
     7         
     8        jwplayer.api = function() {}; 
     9 
     10        jwplayer.api.events = { 
     11                JWPLAYER_READY: 'jwplayerReady', 
     12                JWPLAYER_FULLSCREEN: 'jwplayerFullscreen', 
     13                JWPLAYER_RESIZE: 'jwplayerResize', 
     14                JWPLAYER_ERROR: 'jwplayerError', 
     15                JWPLAYER_MEDIA_BUFFER: 'jwplayerMediaBuffer', 
     16                JWPLAYER_MEDIA_BUFFER_FULL: 'jwplayerMediaBufferFull', 
     17                JWPLAYER_MEDIA_ERROR: 'jwplayerMediaError', 
     18                JWPLAYER_MEDIA_LOADED: 'jwplayerMediaLoaded', 
     19                JWPLAYER_MEDIA_COMPLETE: 'jwplayerMediaComplete', 
     20                JWPLAYER_MEDIA_TIME: 'jwplayerMediaTime', 
     21                JWPLAYER_MEDIA_VOLUME: 'jwplayerMediaVolume', 
     22                JWPLAYER_MEDIA_META: 'jwplayerMediaMeta', 
     23                JWPLAYER_MEDIA_MUTE: 'jwplayerMediaMute', 
     24                JWPLAYER_PLAYER_STATE: 'jwplayerPlayerState', 
     25                JWPLAYER_PLAYLIST_LOADED: 'jwplayerPlaylistLoaded', 
     26                JWPLAYER_PLAYLIST_ITEM: 'jwplayerPlaylistItem' 
     27        }; 
     28         
     29        jwplayer.api.events.state = { 
     30                BUFFERING: 'BUFFERING', 
     31                IDLE: 'IDLE', 
     32                PAUSED: 'PAUSED', 
     33                PLAYING: 'PLAYING' 
     34        }; 
     35         
     36        jwplayer.api.PlayerAPI = function(container) { 
     37                var _listeners = {}; 
     38                var _stateListeners = {}; 
     39                var _player = undefined; 
     40                 
     41                this.container = container; 
     42                this.id = container.id; 
     43                 
     44                this.stateListener = function(state, callback) { 
     45                        if (!_stateListeners[state]) {  
     46                                _stateListeners[state] = [];  
     47                                this.eventListener(jwplayer.api.events.JWPLAYER_PLAYER_STATE, this.stateCallback(state)); 
     48                        }  
     49                        _stateListeners[state].push(callback); 
     50                        return this; 
     51                }; 
     52                 
     53                this.stateCallback = function(state) { 
     54                        return function(newstate, oldstate) { 
     55                                if (newstate == state) { 
     56                                        var callbacks = _stateListeners[newstate]; 
     57                                        if (callbacks) { 
     58                                                for (var c in callbacks) { 
     59                                                        if (typeof callbacks[c] == 'function') { 
     60                                                                callbacks[c].call(this, oldstate); 
     61                                                        } 
     62                                                } 
     63                                        } 
     64                                } 
     65                        }; 
     66                }; 
     67                 
     68                this.eventListener = function(type, callback) { 
     69                        if (!_listeners[type]) { _listeners[type] = []; } 
     70                        _listeners[type].push(callback); 
     71                        return this; 
     72                }; 
     73                 
     74                this.dispatchEvent = function(type) { 
     75                        if (_listeners[type]) { 
     76                                for (var l in _listeners[type]) { 
     77                                        if (typeof _listeners[type][l] == 'function') { 
     78                                                _listeners[type][l].apply(this, slice(arguments, 1)); 
     79                                        } 
     80                                } 
     81                        } 
     82                }; 
     83                 
     84                this.playerReady = function() { 
     85                        _player = this.container; 
     86                }; 
     87                 
     88                /** Using this function instead of array.slice since Arguments are not an array **/ 
     89                function slice(list, from, to) { 
     90                        var ret = []; 
     91                        if (!from) { from = 0; } 
     92                        if (!to) { to = list.length-1; } 
     93                        for (var i=from; i<=to; i++) { 
     94                                ret.push(list[i]); 
     95                        } 
     96                        return ret; 
     97                } 
     98        }; 
     99 
     100        jwplayer.api.PlayerAPI.prototype = { 
     101                // Player properties 
     102                container: undefined, 
     103                options: undefined, 
     104                id: undefined, 
     105                 
     106                // Player Getters 
     107                getBuffer: function() { return undefined; }, 
     108                getFullscreen: function() { return undefined; }, 
     109                getLockState: function() { return undefined; }, 
     110                getMeta: function() { return undefined; }, 
     111                getMute: function() { return undefined; }, 
     112                getPlaylist: function() { return undefined; }, 
     113                getPlaylistItem: function() { return undefined; }, 
     114                getHeight: function() { return undefined; }, 
     115                getWidth: function() { return undefined; }, 
     116                getState: function() { return undefined; }, 
     117                getPosition: function() { return undefined; }, 
     118                getDuration: function() { return undefined; }, 
     119                getVolume: function() { return undefined; }, 
     120                 
     121                // Player Public Methods 
     122                setFullscreen: function() { return this; }, 
     123                setMute: function() { return this; }, 
     124                lock: function() { return this; }, 
     125                unlock: function() { return this; }, 
     126                load: function() { return this; }, 
     127                playlistItem: function() { return this; }, 
     128                playlistPrev: function() { return this; }, 
     129                playlistNext: function() { return this; }, 
     130                resize: function() { return this; }, 
     131                play: function() {  
     132                        this.dispatchEvent(jwplayer.api.events.JWPLAYER_PLAYER_STATE, 'BUFFERING', 'IDLE');  
     133                        this.dispatchEvent(jwplayer.api.events.JWPLAYER_PLAYER_STATE, 'PLAYING', 'BUFFERING');  
     134                        return this;  
     135                }, 
     136                pause: function() {  
     137                        this.dispatchEvent(jwplayer.api.events.JWPLAYER_PLAYER_STATE, 'PAUSED', 'PLAYING');  
     138                        return this;  
     139                }, 
     140                stop: function() {  
     141                        this.dispatchEvent(jwplayer.api.events.JWPLAYER_PLAYER_STATE, 'IDLE', 'PLAYING');  
     142                        return this;  
     143                }, 
     144                seek: function() { return this; }, 
     145                setVolume: function() { return this; }, 
     146                 
     147                // Player Events 
     148                onBufferProgress: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER, callback); }, 
     149                onBufferFull: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER_FULL, callback); }, 
     150                onError: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_ERROR, callback); }, 
     151                onFullscreen: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_FULLSCREEN, callback); }, 
     152                onMeta: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_META, callback); }, 
     153                onMute: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_MUTE, callback); }, 
     154                onPlaylist: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_PLAYLIST_LOADED, callback); }, 
     155                onPlaylistItem: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_PLAYLIST_ITEM, callback); }, 
     156                onReady: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_READY, callback); }, 
     157                onResize: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_RESIZE, callback); }, 
     158                onComplete: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE, callback); }, 
     159                onTime: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_TIME, callback); }, 
     160                onVolume: function(callback) { return this.eventListener(jwplayer.api.events.JWPLAYER_MEDIA_VOLUME, callback); }, 
     161         
     162                // State events 
     163                onBuffer: function(callback) { return this.stateListener(jwplayer.api.events.state.BUFFERING, callback); }, 
     164                onPause: function(callback) { return this.stateListener(jwplayer.api.events.state.PAUSED, callback); }, 
     165                onPlay: function(callback) { return this.stateListener(jwplayer.api.events.state.PLAYING, callback); }, 
     166                onStop: function(callback) { return this.stateListener(jwplayer.api.events.state.IDLE, callback); }, 
     167 
     168                // Player plugin API 
     169                initializePlugin: function(pluginName, pluginCode) { return this; } 
     170        }; 
     171         
     172        jwplayer.api.selectPlayer = function(identifier) { 
     173                var _container; 
     174                 
     175                if (identifier == undefined) identifier = 0; 
     176                 
     177                if (identifier.nodeType) { 
     178                        // Handle DOM Element 
     179                        _container = identifier; 
     180                } else if (typeof identifier == 'string') { 
     181                        // Find container by ID 
     182                        _container = document.getElementById(identifier); 
     183                } 
     184                 
     185                if (_container) {   
     186                        var foundPlayer = jwplayer.api.playerByContainer(_container); 
     187                        if (foundPlayer) { 
     188                                return foundPlayer;  
     189                        } else { 
     190                                // Todo: register new object 
     191                                return new jwplayer.api.PlayerAPI(_container);  
     192                        } 
     193                } else if (typeof identifier == 'number') { 
     194                        return jwplayer.getPlayers()[identifier]; 
     195                } 
     196         
     197                return null; 
     198        }; 
     199         
     200        jwplayer.api.playerByContainer = function(cont) { 
     201                for(var p in _players) { 
     202                        if (_players[p].container == cont) { 
     203                                return _players[p]; 
     204                        } 
     205                } 
     206                return null; 
     207        }; 
     208         
     209        jwplayer.register = jwplayer.api.addPlayer = function(player) { 
     210                for (var i in _players) { 
     211                        if (_players[i] == player) { 
     212                                return player; // Player is already in the list; 
     213                        } 
     214                } 
     215         
     216                _players.push(player); 
     217                return player; 
     218        }; 
     219         
     220        // Can't make this a read-only getter, thanks to IE incompatibility. 
     221        jwplayer.getPlayers = function() {  
     222                return _players.slice(0);  
     223        }; 
     224         
     225        var _userPlayerReady = (typeof playerReady == 'function') ? playerReady : undefined; 
     226         
     227        playerReady = function(obj) { 
     228                var api = jwplayer(obj['id']); 
     229                api.playerReady(); 
     230                 
     231                // Todo: setup event callbacks 
     232                // Todo: run any queued up commands  
     233                 
     234                if (_userPlayerReady) { 
     235                        _userPlayerReady.call(this, obj); 
     236                }                
     237        }; 
     238         
     239})(jwplayer); 
  • trunk/js/src/embed/jwplayer.embed.js

    r1179 r1194  
    1 jwplayer.embed = function() {}; 
     1(function(jwplayer) { 
    22 
    3 jwplayer.embed.Embedder = function(playerApi) { 
    4         this.constructor(playerApi); 
    5 }; 
    6  
    7 jwplayer.embed.Embedder.prototype = { 
    8         api: undefined, 
    9         config: undefined, 
    10         events: {}, 
    11         players: {}, 
    12  
    13         constructor: function(playerApi) { 
    14                 this.api = playerApi; 
    15                 this.config = this.parseConfig(this.api.config); 
    16         }, 
    17  
    18         embedPlayer: function() { 
    19                 var player = this.players[0]; 
    20                 if (player && player.type) { 
    21                         switch (player.type) { 
    22                         case 'flash': 
    23                                 jwplayer.embed.embedFlash(this.api.container, player, this.config); 
     3        jwplayer.embed = function() {}; 
     4         
     5        jwplayer.embed.Embedder = function(playerApi) { 
     6                var events = {}, 
     7                        players = {}, 
     8                        config = undefined, 
     9                        api = undefined; 
     10                 
     11                this.constructor(playerApi); 
     12        }; 
     13         
     14        jwplayer.embed.Embedder.prototype = { 
     15                constructor: function(playerApi) { 
     16                        this.api = playerApi; 
     17                        this.config = this.parseConfig(this.api.config); 
     18                }, 
     19         
     20                embedPlayer: function() { 
     21                        var player = this.players[0]; 
     22                        if (player && player.type) { 
     23                                switch (player.type) { 
     24                                case 'flash': 
     25                                        this.api.container = jwplayer.embed.embedFlash(this.api.container, player, this.config); 
     26                                        break; 
     27                                case 'html5': 
     28                                        this.api.player = jwplayer.embed.embedHTML5(this.api.container, player, this.config); 
     29                                        playerReady({id:this.api.container.id}); 
     30                                        break; 
     31                                } 
     32                        } 
     33                        return jwplayer.register(this.api); 
     34                }, 
     35                 
     36                parseConfig: function(config) { 
     37                        var parsedConfig = jwplayer.utils.extend({}, config); 
     38                        if(parsedConfig.events) { 
     39                                this.events = parsedConfig.events; 
     40                                delete parsedConfig['events']; 
     41                        } 
     42                        if(parsedConfig.players) { 
     43                                this.players = parsedConfig.players; 
     44                                delete parsedConfig['players']; 
     45                        } 
     46                        if(parsedConfig.plugins) { 
     47                                if (typeof parsedConfig.plugins == "object") { 
     48                                        parsedConfig = jwplayer.utils.extend(parsedConfig, jwplayer.embed.parsePlugins(parsedConfig.plugins)); 
     49                                } 
     50                        } 
     51                        return parsedConfig; 
     52                } 
     53         
     54        }; 
     55         
     56        jwplayer.embed.defaults = { 
     57                width: 400, 
     58                height: 300 
     59        }; 
     60         
     61        jwplayer.embed.embedFlash = function(container, player, options) { 
     62                var params = jwplayer.utils.extend({}, jwplayer.embed.defaults, options); 
     63                 
     64                var width = params.width;  
     65                delete params['width']; 
     66                 
     67                var height = params.height;  
     68                delete params['height']; 
     69                 
     70                if (jwplayer.utils.isIE()) { 
     71                        var html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +  
     72                                'width="' + width + '" height="' + height + '" ' + 
     73                                'id="' + container.id + '" name="' + container.id + 
     74                                '">'; 
     75                        html += '<param name="movie" value="' + player.src + '">'; 
     76                        html += '<param name="allowfullscreen" value="true">'; 
     77                        html += '<param name="allowscriptaccess" value="always">'; 
     78                        html += '<param name="flashvars" value="' + jwplayer.embed.jsonToFlashvars(params) +'">'; 
     79                        html += '</object>'; 
     80                        container.outerHTML = html; 
     81                        return container; 
     82                } else { 
     83                        var obj = document.createElement('object'); 
     84                        obj.setAttribute('type', 'application/x-shockwave-flash'); 
     85                        obj.setAttribute('data', player.src); 
     86                        obj.setAttribute('width', width); 
     87                        obj.setAttribute('height', height); 
     88                        obj.setAttribute('id', container.id); 
     89                        obj.setAttribute('name', container.id); 
     90                        jwplayer.embed.appendAttribute(obj, 'allowfullscreen', 'true'); 
     91                        jwplayer.embed.appendAttribute(obj, 'allowscriptaccess', 'always'); 
     92                        jwplayer.embed.appendAttribute(obj, 'flashvars', jwplayer.embed.jsonToFlashvars(params)); 
     93                        container.parentNode.replaceChild(obj, container); 
     94                        return obj; 
     95                } 
     96        }; 
     97         
     98        jwplayer.embed.embedHTML5 = function(container, player, options) { 
     99                if (jwplayer.html5) { 
     100                        var player = new (jwplayer.html5(container)).setup(jwplayer.utils.extend({}, jwplayer.embed.defaults, options)); 
     101                        return player; 
     102                } else { 
     103                        return null; 
     104                } 
     105        }; 
     106         
     107        jwplayer.embed.appendAttribute = function(object, name, value) { 
     108                var param = document.createElement('param'); 
     109                param.setAttribute('name', name); 
     110                param.setAttribute('value', value); 
     111                object.appendChild(param); 
     112        }; 
     113         
     114        jwplayer.embed.jsonToFlashvars = function(json) { 
     115                var flashvars = ''; 
     116                for (key in json) { 
     117                        flashvars += key + '=' + escape(json[key]) + '&'; 
     118                } 
     119                return flashvars.substring(0, flashvars.length-1); 
     120        }; 
     121         
     122        jwplayer.embed.parsePlugins = function(pluginBlock) { 
     123                if (!pluginBlock) return {}; 
     124                 
     125                var flat = {}, 
     126                        pluginKeys = []; 
     127                 
     128                for (plugin in pluginBlock) { 
     129                        var pluginName = plugin.indexOf('-') > 0 ? plugin.substring(0, plugin.indexOf('-')) : plugin; 
     130                        var pluginConfig = pluginBlock[plugin]; 
     131                        pluginKeys.push(plugin); 
     132                        for (param in pluginConfig) { 
     133                                flat[pluginName+'.'+param] = pluginConfig[param]; 
    24134                        } 
    25135                } 
    26                  
    27                 return this.api; 
    28         }, 
     136                flat['plugins'] = pluginKeys.join(',');  
     137                return flat; 
     138        }; 
    29139         
    30         parseConfig: function(config) { 
    31                 var parsedConfig = jwplayer.utils.extend({}, config); 
    32                 if(parsedConfig.events) { 
    33                         this.events = parsedConfig.events; 
    34                         delete parsedConfig['events']; 
    35                 } 
    36                 if(parsedConfig.players) { 
    37                         this.players = parsedConfig.players; 
    38                         delete parsedConfig['players']; 
    39                 } 
    40                 return parsedConfig; 
    41         } 
     140        jwplayer.api.PlayerAPI.prototype.setup = function(options, player) { 
     141                this.config = options; 
     142                if(player) { this.player = player; } 
     143                jwplayer.register(this); 
     144                return (new jwplayer.embed.Embedder(this)).embedPlayer(); 
     145        }; 
    42146         
    43 }; 
    44  
    45 jwplayer.embed.defaults = { 
    46         width: 400, 
    47         height: 300 
    48 }; 
    49  
    50 jwplayer.embed.embedFlash = function(container, player, options) { 
    51         var params = jwplayer.utils.extend({}, jwplayer.embed.defaults, options); 
    52          
    53         var width = params.width;  
    54         delete params['width']; 
    55          
    56         var height = params.height;  
    57         delete params['height']; 
    58          
    59         if (jwplayer.utils.isIE()) { 
    60                 var html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +  
    61                         'width="' + width + '" height="' + height + '" ' + 
    62                         'id="' + container.id + '" name="' + container.id + 
    63                         '">'; 
    64                 html += '<param name="movie" value="' + player.src + '">'; 
    65                 html += '<param name="allowfullscreen" value="true">'; 
    66                 html += '<param name="allowscriptaccess" value="always">'; 
    67                 html += '<param name="flashvars" value="' + jwplayer.embed.jsonToFlashvars(params) +'">'; 
    68                 html += '</object>'; 
    69                 container.outerHTML = html; 
    70         } else { 
    71                 var obj = document.createElement('object'); 
    72                 obj.setAttribute('type', 'application/x-shockwave-flash'); 
    73                 obj.setAttribute('data', player.src); 
    74                 obj.setAttribute('width', width); 
    75                 obj.setAttribute('height', height); 
    76                 obj.setAttribute('id', container.id); 
    77                 obj.setAttribute('name', container.id); 
    78                 jwplayer.embed.appendAttribute(obj, 'allowfullscreen', 'true'); 
    79                 jwplayer.embed.appendAttribute(obj, 'allowscriptaccess', 'always'); 
    80                 jwplayer.embed.appendAttribute(obj, 'flashvars', jwplayer.embed.jsonToFlashvars(params)); 
    81                 container.parentNode.replaceChild(obj, container); 
    82         } 
    83 }; 
    84  
    85 jwplayer.embed.appendAttribute = function(object, name, value) { 
    86         var param = document.createElement('param'); 
    87         param.setAttribute('name', name); 
    88         param.setAttribute('value', value); 
    89         object.appendChild(param); 
    90 }; 
    91  
    92 jwplayer.embed.jsonToFlashvars = function(json) { 
    93         var flashvars = ''; 
    94         for (key in json) { 
    95                 flashvars += key + '=' + escape(json[key]) + '&'; 
    96         } 
    97         return flashvars.substring(0, flashvars.length-1); 
    98 }; 
    99  
    100 jwplayer.api.PlayerAPI.prototype.setup = function(options, player) { 
    101         this.config = options; 
    102         this.player = player; 
    103         return (new jwplayer.embed.Embedder(this)).embedPlayer(); 
    104 }; 
     147})(jwplayer); 
  • trunk/js/test/index.php

    r1192 r1194  
    66<script type="text/javascript" src="files/swfobject.js"></script> 
    77<script type="text/javascript" src="settings.js"></script> 
     8<script type="text/javascript" src="../bin-debug/jwplayer.js"></script> 
    89<script type="text/javascript"> 
    9  
    10  
    1110 
    1211 
     
    233232                var lnk = 'http://developer.longtailvideo.com/trac/testing/'; 
    234233                $("#permalink").val(lnk+'?'+$.param(variables)); 
     234   } 
     235 
     236   function jwplayersetup() { 
     237        var temp = getVariables(); 
     238        var vrs = temp['vrs']; 
     239        var variables = temp['variables']; 
     240 
     241        jwplayer('preview').setup($.extend(vrs, { 
     242                players:[ 
     243                        {type:'flash',src:settings.players[$('#players').val()]} 
     244                ] 
     245        })); 
    235246   } 
    236247 
  • trunk/js/test/settings.js

    r1192 r1194  
    44    "default": "<div id='preview'><p>Testing is simple: choose an example, change the flashvars and see if it works.</p></div>", 
    55    "object": "<embed id='preview' name='preview' src='players/player-5.2.swf' width='470' height='320' bgcolor='#000000' allowscriptaccess='always' allowfullscreen='true' flashvars='file=http://content.longtailvideo.com/videos/flvplayer.flv' />", 
    6     "embed": "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='470' height='320' id='single1' name='single1'><param name='movie' value='players/player-5.2.swf'><param name='allowfullscreen' value='true'> <param name='allowscriptaccess' value='always'> <param name='wmode' value='transparent'>  <param name='flashvars' value='file=http://content.longtailvideo.com/videos/flvplayer.flv'>", 
     6    "embed": "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='470' height='320' id='preview' name='preview'><param name='movie' value='players/player-5.2.swf'><param name='allowfullscreen' value='true'> <param name='allowscriptaccess' value='always'> <param name='wmode' value='transparent'>  <param name='flashvars' value='file=http://content.longtailvideo.com/videos/flvplayer.flv'>", 
    77    "video": "<video id='preview' height='270' poster='files/bunny.jpg' src='files/bunny.mp4' width='480'></video>" 
    88  }, 
    99  /** The embed script to use **/ 
    1010  "script":{ 
    11     "none":"", 
    12     "swfobject":"swfobjectembed" 
     11    "none":"(function() {})", 
     12    "swfobject":"swfobjectembed", 
     13    "jwembed":"jwplayersetup" 
    1314  }, 
    1415        /** Player versions to test. **/ 
     
    6869                " ": {}, 
    6970                "FLV video": { 
    70                         "file":"../../testing/files/bunny.flv", 
     71                        "file":"../files/bunny.flv", 
    7172                        "image":"files/bunny.jpg", 
    7273                        "height":240, 
     
    7475                }, 
    7576                "MP4 video": { 
    76                         "file":"../../testing/files/bunny.mp4", 
     77                        "file":"../files/bunny.mp4", 
    7778                        "image":"files/bunny.jpg", 
    7879                        "height":240, 
     
    8586                }, 
    8687                "AAC audio":{ 
    87                         "file":"../../testing/files/bunny.m4a", 
     88                        "file":"../files/bunny.m4a", 
    8889                        "image":"files/bunny.jpg", 
    8990                        "height":240, 
     
    206207                " ": {}, 
    207208                "Agegate plugin": { 
    208                         "file":"../../testing/files/corrie.flv", 
     209                        "file":"../files/corrie.flv", 
    209210                        "height":240, 
    210211                        "width":500, 
     
    213214                }, 
    214215                "Audiodescription and captions plugins": { 
    215                         "file":"../../testing/files/corrie.flv", 
     216                        "file":"../files/corrie.flv", 
    216217                        "height":240, 
    217218                        "width":500, 
     
    235236                }, 
    236237                "HD plugin": { 
    237                         "file":"../../testing/files/bunny.flv", 
     238                        "file":"../files/bunny.flv", 
    238239                        "height":240, 
    239240                        "width":500, 
    240241                        "plugins":"hd", 
    241242                        "dock":"true", 
    242                         "hd.file":"../../testing/files/bunny.mp4" 
     243                        "hd.file":"../files/bunny.mp4" 
    243244                }, 
    244245                "Searchbar plugin": { 
     
    252253                "Sharing plugin": { 
    253254                        "dock":true, 
    254                         "file":"../../testing/files/bunny.flv", 
     255                        "file":"../files/bunny.flv", 
    255256                        "height":260, 
    256257                        "width":460, 
Note: See TracChangeset for help on using the changeset viewer.