Changeset 2047
- Timestamp:
- 01/11/12 19:06:36 (17 months ago)
- Location:
- branches/fl5_instream
- Files:
-
- 14 edited
-
js/bin-debug/jwplayer.js (modified) (58 diffs)
-
js/src/events/jwplayer.events.eventdispatcher.js (modified) (1 diff)
-
js/src/html5/jwplayer.html5.api.js (modified) (4 diffs)
-
js/src/html5/jwplayer.html5.controlbar.js (modified) (1 diff)
-
js/src/html5/jwplayer.html5.controller.js (modified) (9 diffs)
-
js/src/html5/jwplayer.html5.display.js (modified) (6 diffs)
-
js/src/html5/jwplayer.html5.instream.js (modified) (1 diff)
-
js/src/html5/jwplayer.html5.mediavideo.js (modified) (28 diffs)
-
js/src/html5/jwplayer.html5.view.js (modified) (7 diffs)
-
js/src/jwplayer.js (modified) (1 diff)
-
js/test/examples/instream.html (modified) (6 diffs)
-
js/test/examples/settings.js (modified) (1 diff)
-
player.swf (modified) (previous)
-
src/com/longtailvideo/jwplayer/player/PlayerVersion.as (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/fl5_instream/js/bin-debug/jwplayer.js
r2043 r2047 19 19 var $jw = jwplayer; 20 20 21 jwplayer.version = '5.9.204 3';21 jwplayer.version = '5.9.2047'; 22 22 23 23 // "Shiv" method for older IE browsers; required for parsing media tags … … 987 987 /** Add an event listener for all events. **/ 988 988 this.removeGlobalListener = function(listener) { 989 if (! _globallisteners[type]) {989 if (!listener) { 990 990 return; 991 991 } … … 4236 4236 var _falseFullscreen = false; 4237 4237 var _normalscreenWidth, _normalscreenHeight; 4238 var _instremArea ;4238 var _instremArea, _instreamMode; 4239 4239 4240 4240 function createWrapper() { … … 4318 4318 4319 4319 function _stateHandler(evt) { 4320 _css(_box, { 4321 display: (_model.getMedia() && _model.getMedia().hasChrome() && evt.newstate != jwplayer.api.events.state.IDLE) ? "none" : "block" 4322 }); 4320 if (_instreamMode) { return; } 4321 4322 if (_model.getMedia() && _model.getMedia().hasChrome()) { 4323 _box.style.display = "block"; 4324 } else { 4325 switch (evt.newstate) { 4326 case evt.newstate == jwplayer.api.events.state.PLAYING: 4327 _box.style.display = "none"; 4328 break; 4329 default: 4330 _box.style.display = "block"; 4331 break; 4332 } 4333 } 4323 4334 } 4324 4335 … … 4351 4362 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_PLAYER_STATE, _stateHandler); 4352 4363 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_MEDIA_LOADED, _loadedHandler); 4353 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_MEDIA_META, function( ) {4364 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_MEDIA_META, function(evt) { 4354 4365 _resizeMedia(); 4355 4366 }); … … 4528 4539 } 4529 4540 4530 function _resizeMedia() {4541 var _resizeMedia = this.resizeMedia = function() { 4531 4542 if (!_utils.exists(_model.getMedia())) { 4532 4543 return; … … 4574 4585 } 4575 4586 4576 function _getComponentPosition(pluginName) {4587 var _getComponentPosition = this.getComponentPosition = function(pluginName) { 4577 4588 var plugincss = { 4578 4589 position: "absolute", … … 4699 4710 return false; 4700 4711 } 4701 /// public function setupInstream(_instreamDisplay:DisplayObject, plugin:IPlugin):void {4702 4712 4703 4713 this.setupInstream = function(instreamDisplay) { … … 4705 4715 _box.style.display = "none"; 4706 4716 _instreamArea.appendChild(instreamDisplay); 4707 }4708 4709 /// public function destroyInstream():void {4717 _instreamMode = true; 4718 } 4719 4710 4720 var _destroyInstream = this.destroyInstream = function() { 4711 4721 _instreamArea.style.display = "none"; 4722 _instreamArea.innerHTML = ""; 4712 4723 _box.style.display = "block"; 4713 } 4714 }; 4715 4716 4717 //TODO: Enum 4724 _instreamMode = false; 4725 _resize(_model.width, _model.height); 4726 } 4727 }; 4728 4729 4718 4730 jwplayer.html5.view.positions = { 4719 4731 TOP: "TOP", … … 5605 5617 _hide(_elements.muteButton); 5606 5618 _show(_elements.unmuteButton); 5619 _hide(_elements.volumeSliderProgress); 5607 5620 } else { 5608 5621 _show(_elements.muteButton); 5609 5622 _hide(_elements.unmuteButton); 5623 _show(_elements.volumeSliderProgress); 5610 5624 } 5611 5625 } … … 5747 5761 _preplay = false, 5748 5762 _interruptPlay = false, 5763 _actionOnAttach, 5749 5764 _queuedEvents = [], 5750 5765 _ready = false; … … 5816 5831 function _play() { 5817 5832 try { 5833 _actionOnAttach = _play; 5818 5834 if (!_preplay) { 5819 5835 _preplay = true; … … 5822 5838 if (_interruptPlay) { 5823 5839 _interruptPlay = false; 5840 _actionOnAttach = null; 5824 5841 return; 5825 5842 } … … 5838 5855 } catch (err) { 5839 5856 _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_ERROR, err); 5857 _actionOnAttach = null; 5840 5858 } 5841 5859 return false; … … 5902 5920 /** Stop playback and loading of the video. **/ 5903 5921 function _stop(clear) { 5922 _actionOnAttach = null; 5904 5923 if (!_utils.exists(clear)) { 5905 5924 clear = true; … … 6043 6062 break; 6044 6063 } 6064 _model.volume = volume; 6045 6065 return true; 6046 6066 } catch (err) { … … 6174 6194 function _attachMedia() { 6175 6195 try { 6176 return _model.getMedia().attachMedia(); 6196 var ret = _model.getMedia().attachMedia(); 6197 if (typeof _actionOnAttach == "function") { 6198 _actionOnAttach(); 6199 } 6177 6200 } catch (err) { 6178 6201 return null; … … 6188 6211 6189 6212 function _completeHandler() { 6213 _actionOnAttach = _completeHandler; 6190 6214 switch (_model.config.repeat.toUpperCase()) { 6191 6215 case jwplayer.html5.controller.repeatoptions.SINGLE: … … 6247 6271 this.playerReady = _playerReady; 6248 6272 this.detachMedia = _detachMedia; 6249 this.attachMedia = _attachMedia; 6273 this.attachMedia = _attachMedia; 6274 this.beforePlay = function() { 6275 return _preplay; 6276 } 6250 6277 }; 6251 6278 })(jwplayer); … … 6590 6617 return; 6591 6618 } 6619 6592 6620 _lastState = state; 6593 6621 … … 6618 6646 switch (state) { 6619 6647 case jwplayer.api.events.state.BUFFERING: 6620 if (_utils.is Mobile()) {6648 if (_utils.isIPod()) { 6621 6649 _resetPoster(); 6622 6650 _hideDisplayIcon(); 6623 6651 } else { 6624 if (_api.jwGetPlaylist()[_api.jwGet Item()].provider == "sound") {6652 if (_api.jwGetPlaylist()[_api.jwGetPlaylistIndex()].provider == "sound") { 6625 6653 _showImage(); 6626 6654 } … … 6635 6663 break; 6636 6664 case jwplayer.api.events.state.PAUSED: 6637 if (!_utils.is Mobile()) {6638 if (_api.jwGetPlaylist()[_api.jwGet Item()].provider != "sound") {6665 if (!_utils.isIPod()) { 6666 if (_api.jwGetPlaylist()[_api.jwGetPlaylistIndex()].provider != "sound") { 6639 6667 _css(_display.display_image, { 6640 6668 background: "transparent no-repeat center center" … … 6646 6674 break; 6647 6675 case jwplayer.api.events.state.IDLE: 6648 if (_api.jwGetPlaylist()[_api.jwGet Item()] && _api.jwGetPlaylist()[_api.jwGetItem()].image) {6676 if (_api.jwGetPlaylist()[_api.jwGetPlaylistIndex()] && _api.jwGetPlaylist()[_api.jwGetPlaylistIndex()].image) { 6649 6677 _showImage(); 6650 6678 } else { … … 6655 6683 break; 6656 6684 default: 6657 if (_api.jwGetPlaylist()[_api.jwGet Item()] && _api.jwGetPlaylist()[_api.jwGetItem()].provider == "sound") {6658 if (_utils.is Mobile()) {6685 if (_api.jwGetPlaylist()[_api.jwGetPlaylistIndex()] && _api.jwGetPlaylist()[_api.jwGetPlaylistIndex()].provider == "sound") { 6686 if (_utils.isIPod()) { 6659 6687 _resetPoster(); 6660 6688 _showing = false; … … 6677 6705 6678 6706 function _showImage() { 6679 if (_api.jwGetPlaylist()[_api.jwGet Item()] && _api.jwGetPlaylist()[_api.jwGetItem()].image) {6707 if (_api.jwGetPlaylist()[_api.jwGetPlaylistIndex()] && _api.jwGetPlaylist()[_api.jwGetPlaylistIndex()].image) { 6680 6708 _css(_display.display_image, { 6681 6709 display: "block" 6682 6710 }); 6683 _display.display_image.src = _utils.getAbsolutePath(_api.jwGetPlaylist()[_api.jwGet Item()].image);6711 _display.display_image.src = _utils.getAbsolutePath(_api.jwGetPlaylist()[_api.jwGetPlaylistIndex()].image); 6684 6712 } 6685 6713 } … … 7049 7077 var _utils = jwplayer.utils; 7050 7078 7051 jwplayer.html5.instream = function(item, options, api, model, view, controller) { 7052 var _item = new jwplayer.html5.playlistitem(item), 7053 _api = api, 7054 _options = options, 7055 _model = model, 7056 _view = view, 7057 _controller = controller, 7058 _currentItem = _model.item, 7059 _currentPlaylist = _model.playlist, 7060 _video, _oldsrc, _oldsources, _oldpos, 7061 _self = this, 7062 _provider, _cbar, 7079 jwplayer.html5.instream = function(api, model, view, controller) { 7080 var _defaultOptions = { 7081 controlbarseekable:"always", 7082 controlbarpausable:true, 7083 controlbarstoppable:true, 7084 playlistclickable:true 7085 }; 7086 7087 var _item, 7088 _options, 7089 _api=api, _model=model, _view=view, _controller=controller, 7090 _video, _oldsrc, _oldsources, _oldpos, _oldstate, _olditem, 7091 _provider, _cbar, _disp, _instreamMode = false, 7092 _dispatcher, _instreamContainer, 7093 _self = this; 7094 7095 7096 /***************************************** 7097 ***** Public instream API methods ***** 7098 *****************************************/ 7099 7100 /** Load an instream item and initialize playback **/ 7101 this.load = function(item, options) { 7102 // Update the instream player's model 7103 _copyModel(); 7104 // Sets internal instream mode to true 7105 _instreamMode = true; 7106 // Instream playback options 7107 _options = _utils.extend(_defaultOptions, options); 7108 // Copy the playlist item passed in and make sure it's formatted as a proper playlist item 7109 _item = jwplayer.html5.playlistitem(item); 7110 // Create (or reuse) video media provider. No checks right now to make sure it's a valid playlist item (i.e. provider="video"). 7111 _setupProvider(); 7112 // Create the container in which the controls will be placed 7113 _instreamContainer = document.createElement("div"); 7114 _instreamContainer.id = _self.id + "_instream_container"; 7115 // Get the video tag, and make sure the original player's provider stops broadcasting events (pseudo-lock...) 7116 _video = _controller.detachMedia(); 7117 // Store this to compare later (in case the main player switches to the next playlist item when we switch out of instream playback mode 7118 _olditem = _model.playlist[_model.item]; 7119 // Keep track of the original player state 7120 _oldstate = _api.jwGetState(); 7121 // If the player's currently playing, pause the video tag 7122 if (_oldstate == jwplayer.api.events.state.BUFFERING || _oldstate == jwplayer.api.events.state.PLAYING) { 7123 _video.pause(); 7124 } 7125 7126 // Copy the video src/sources tags and store the current playback time 7127 _oldsrc = _video.src; 7128 _oldsources = _video.innerHTML; 7129 _oldpos = _video.currentTime; 7130 7131 // Instream display component 7132 _disp = new jwplayer.html5.display(_self, _utils.extend({},_model.plugins.config.display)); 7133 _instreamContainer.appendChild(_disp.getDisplayElement()); 7134 7135 // Instream controlbar (if not iOS/Android) 7136 if (!_utils.isMobile()) { 7137 _cbar = new jwplayer.html5.controlbar(_self, _utils.extend({},_model.plugins.config.controlbar, {})); 7138 _instreamContainer.appendChild(_cbar.getDisplayElement()); 7139 } 7140 7141 // Show the instream layer 7142 _view.setupInstream(_instreamContainer); 7143 // Resize the instream components to the proper size 7144 _resize(_model.plugins.config.display.width, _model.plugins.config.display.height); 7145 // Load the instream item and begin playback 7146 _provider.load(_item); 7147 } 7148 7149 /** Stop the instream playback and revert the main player back to its original state **/ 7150 this.jwInstreamDestroy = function(complete) { 7151 if (!_instreamMode) return; 7152 // We're not in instream mode anymore. 7153 _instreamMode = false; 7154 // Load the original item into our provider, which sets up the regular player's video tag 7155 _provider.load(_olditem, false); 7156 // We don't want the position interval to be running anymore 7157 _provider.stop(false); 7158 // We don't want the instream provider to be attached to the video tag anymore 7159 _provider.detachMedia(); 7160 // Return the view to its normal state 7161 _view.destroyInstream(); 7162 // Let listeners know the instream player has been destroyed, and why 7163 _sendEvent(jwplayer.api.events.JWPLAYER_INSTREAM_DESTROYED, {reason:(complete ? "complete":"destroyed")}, true); 7164 // Re-attach the controller 7165 _controller.attachMedia(); 7166 if (_oldstate == jwplayer.api.events.state.BUFFERING || _oldstate == jwplayer.api.events.state.PLAYING) { 7167 // Model was already correct; just resume playback 7168 _video.play(); 7169 if (_model.playlist[_model.item] == _olditem) { 7170 // We need to seek using the player's real provider, since the seek may have to be delayed 7171 _model.getMedia().seek(_oldpos); 7172 } 7173 } 7174 return; 7175 }; 7176 7177 /** Forward any calls to add and remove events directly to our event dispatcher **/ 7178 this.jwInstreamAddEventListener = function(type, listener) { 7179 _dispatcher.addEventListener(type, listener); 7180 } 7181 this.jwInstreamRemoveEventListener = function(type, listener) { 7182 _dispatcher.removeEventListener(type, listener); 7183 } 7184 7185 /** Start instream playback **/ 7186 this.jwInstreamPlay = function() { 7187 if (!_instreamMode) return; 7188 _provider.play(true); 7189 } 7190 7191 /** Pause instream playback **/ 7192 this.jwInstreamPause = function() { 7193 if (!_instreamMode) return; 7194 _provider.pause(true); 7195 } 7196 7197 /** Seek to a point in instream media **/ 7198 this.jwInstreamSeek = function(position) { 7199 if (!_instreamMode) return; 7200 _provider.seek(position); 7201 } 7202 7203 /** Get the current instream state **/ 7204 this.jwInstreamGetState = function() { 7205 if (!_instreamMode) return undefined; 7206 return _fakemodel.state; 7207 } 7208 7209 /** Get the current instream playback position **/ 7210 this.jwInstreamGetPosition = function() { 7211 if (!_instreamMode) return undefined; 7212 return _fakemodel.position; 7213 } 7214 7215 /** Get the current instream media duration **/ 7216 this.jwInstreamGetDuration = function() { 7217 if (!_instreamMode) return undefined; 7218 return _fakemodel.duration; 7219 } 7220 7221 this.playlistClickable = function() { 7222 return (!_instreamMode || _options.playlistclickable.toString().toLowerCase()=="true"); 7223 } 7224 7225 7226 /***************************** 7227 ****** Private methods ****** 7228 *****************************/ 7229 7230 function _init() { 7231 // Initialize the instream player's model copied from main player's model 7232 _fakemodel = new jwplayer.html5.model(this, _model.getMedia() ? _model.getMedia().getDisplayElement() : _model.container, _model); 7233 // Create new event dispatcher 7063 7234 _dispatcher = new jwplayer.html5.eventdispatcher(); 7064 7065 7066 function _init() { 7067 var _thing = document.createElement("div"); 7068 _thing.id = _self.id; 7069 7070 _controller.pause(); 7071 _video = _controller.detachMedia(); 7072 // _video.style.zIndex = 10; 7073 7074 7075 _oldsrc = _video.src; 7076 _oldsources = _video.getElementsByTagName("source"); 7077 _oldpos = _video.currentPosition; 7078 7079 _view.setupInstream(_thing); 7080 7081 _setupProvider(); 7082 7083 _cbar = new jwplayer.html5.controlbar(_self, _utils.extend({},_model.plugins.config.controlbar, {position:"OVER"})); 7084 7085 _thing.appendChild(_cbar.getDisplayElement()); 7086 7087 7088 _resize(_api.jwGetWidth(), _api.jwGetHeight()); 7089 7090 _provider.load(_item); 7091 7092 return; 7093 }; 7235 // Listen for player resize events 7236 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_RESIZE, function(evt) { 7237 _resize(evt.width, evt.height); 7238 }); 7239 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_FULLSCREEN, function(evt) { 7240 _resize(evt.width, evt.height); 7241 }); 7242 } 7243 7244 function _copyModel() { 7245 _fakemodel.mute = _model.mute; 7246 _fakemodel.volume = _model.volume; 7247 } 7094 7248 7095 7249 function _setupProvider() { 7096 _provider = new jwplayer.html5.mediavideo(_model, _model.getMedia() ? _model.getMedia().getDisplayElement() : _model.container); 7097 _provider.addGlobalListener( 7098 function(evt) { 7099 _dispatcher.sendEvent(evt.type, evt); 7100 } 7101 ); 7102 _provider.addEventListener(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE, function(evt) { 7103 _self.jwInstreamDestroy(); 7104 }); 7105 } 7106 7250 if (!_provider) { 7251 _provider = new jwplayer.html5.mediavideo(_fakemodel, _model.getMedia() ? _model.getMedia().getDisplayElement() : _model.container); 7252 _provider.addGlobalListener(_forward); 7253 _provider.addEventListener(jwplayer.api.events.JWPLAYER_MEDIA_META, _metaHandler); 7254 _provider.addEventListener(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE, _completeHandler); 7255 } 7256 _provider.attachMedia(); 7257 } 7258 7259 /** Forward provider events to listeners **/ 7260 function _forward(evt) { 7261 if (_instreamMode) { 7262 _sendEvent(evt.type, evt); 7263 } 7264 } 7265 7266 /** Handle the JWPLAYER_MEDIA_COMPLETE event **/ 7267 function _completeHandler(evt) { 7268 if (_instreamMode) { 7269 setTimeout(function() { 7270 _self.jwInstreamDestroy(true); 7271 }, 10); 7272 } 7273 } 7274 7275 /** Handle the JWPLAYER_MEDIA_META event **/ 7276 function _metaHandler(evt) { 7277 // If we're getting video dimension metadata from the provider, allow the view to resize the media 7278 if (evt.metadata.width && evt.metadata.height) { 7279 _view.resizeMedia(); 7280 } 7281 } 7282 7283 function _sendEvent(type, data, forceSend) { 7284 if (_instreamMode || forceSend) { 7285 _dispatcher.sendEvent(type, data); 7286 } 7287 } 7288 7289 // Resize handler; resize the components. 7107 7290 function _resize(width, height) { 7108 _css(_cbar.getDisplayElement(), { 7109 position: "absolute", 7110 width: width, 7111 height: height, 7112 zIndex: 1000 7113 }); 7114 _cbar.resize(width, height); 7115 } 7116 7117 this.jwInstreamAddEventListener = _dispatcher.addEventListener; 7118 this.jwInstreamRemoveEventListener = _dispatcher.removeEventListener; 7119 7120 this.jwInstreamPlay = function() { 7121 } 7122 7123 this.jwInstreamPause = function() { 7124 } 7125 7126 this.jwInstreamSeek = function(position) { 7127 } 7128 7129 7130 this.jwInstreamGetState = function() { 7131 } 7132 7133 this.jwInstreamGetPosition = function() { 7134 } 7135 7136 this.jwInstreamGetDuration = function() { 7137 } 7138 7139 this.jwInstreamDestroy = function() { 7140 _video.pause(); 7141 _video.src = _oldsrc; 7142 for (var i=0; i < _oldsources.length; i++) { 7143 _video.appendChild(_oldsources[i]); 7144 } 7145 _video.currentPosition = _oldpos; 7146 _video.load(); 7147 _view.destroyInstream(); 7148 7149 _controller.attachMedia(); 7150 // _model.getMedia().load(_currentPlaylist[_currentItem]); 7151 // _video.pause(); 7152 //_utils.setOuterHTML(_video, _videoHTML); 7153 } 7154 7155 7156 /** Duplicate main html5 api **/ 7157 this.skin = _api.skin; 7158 7159 this.jwPlay = function(state) {}; 7160 this.jwPause = function(state) {}; 7161 this.jwSeek = function(position) {}; 7162 this.jwStop = function() {}; 7163 this.jwGetItem = function() {}; 7291 if (_cbar) { 7292 var originalBar = _view.getComponentPosition('controlbar'); 7293 _css(_cbar.getDisplayElement(), _utils.extend({}, originalBar, { 7294 position: "absolute", 7295 zIndex: 1001 7296 })); 7297 _cbar.resize(originalBar.width, originalBar.height); 7298 } 7299 if (_disp) { 7300 var originalDisp = _view.getComponentPosition('display'); 7301 _css(_disp.getDisplayElement(), _utils.extend({}, originalDisp, { 7302 position: "absolute", 7303 zIndex: 1000 7304 })); 7305 _disp.resize(originalDisp.width, originalDisp.height); 7306 } 7307 if (_view) { 7308 _view.resizeMedia(); 7309 } 7310 } 7311 7312 7313 /************************************** 7314 ***** Duplicate main html5 api ***** 7315 **************************************/ 7316 7317 this.jwPlay = function(state) { 7318 if (_options.controlbarpausable.toString().toLowerCase()=="true") { 7319 this.jwInstreamPlay(); 7320 } 7321 }; 7322 7323 this.jwPause = function(state) { 7324 if (_options.controlbarpausable.toString().toLowerCase()=="true") { 7325 this.jwInstreamPause(); 7326 } 7327 }; 7328 7329 this.jwStop = function() { 7330 if (_options.controlbarstoppable.toString().toLowerCase()=="true") { 7331 this.jwInstreamDestroy(); 7332 } 7333 }; 7334 7335 this.jwSeek = function(position) { 7336 switch(_options.controlbarseekable.toLowerCase()) { 7337 case "always": 7338 this.jwInstreamSeek(position); 7339 break; 7340 case "backwards": 7341 if (_fakemodel.position > position) { 7342 this.jwInstreamSeek(position); 7343 } 7344 break; 7345 } 7346 }; 7347 7164 7348 this.jwGetPosition = function() {}; 7165 7349 this.jwGetDuration = function() {}; 7166 7167 7350 this.jwGetWidth = _api.jwGetWidth; 7168 7351 this.jwGetHeight = _api.jwGetHeight; 7169 7170 7352 this.jwGetFullscreen = _api.jwGetFullscreen; 7171 7353 this.jwSetFullscreen = _api.jwSetFullscreen; 7172 7173 this.jwGetVolume = _api.jwGetVolume; 7174 this.jwSetVolume = _api.jwSetVolume; 7175 7176 this.jwGetMute = _api.jwGetMute; 7177 this.jwSetMute = _api.setMute; 7178 7179 this.jwGetState = function() {}; 7180 7181 this.jwGetPlaylist = function() { 7182 return [_item]; 7183 }; 7184 this.jwGetPlaylistIndex = function() { 7185 return 0; 7186 }; 7187 7188 this.jwAddEventListener = function(type, handler) { 7189 _dispatcher.addEventListener(type, handler); 7190 } 7191 this.jwRemoveEventListener = _dispatcher.removeEventListener; 7192 7354 this.jwGetVolume = function() { return _model.volume; }; 7355 this.jwSetVolume = function(vol) { 7356 _provider.volume(vol); 7357 _api.jwSetVolume(vol); 7358 } 7359 this.jwGetMute = function() { return _model.mute; }; 7360 this.jwSetMute = function(state) { 7361 _provider.mute(state); 7362 _api.jwSetMute(state); 7363 } 7364 this.jwGetState = function() { return _fakemodel.state; }; 7365 this.jwGetPlaylist = function() { return [_item]; }; 7366 this.jwGetPlaylistIndex = function() { return 0; }; 7367 this.jwGetStretching = function() { return _model.config.stretching; }; 7368 this.jwAddEventListener = function(type, handler) { _dispatcher.addEventListener(type, handler); }; 7369 this.jwRemoveEventListener = function(type, handler) { _dispatcher.removeEventListener(type, handler); }; 7370 7371 this.skin = _api.skin; 7193 7372 this.id = _api.id; 7194 7373 7195 7374 _init(); 7196 7197 7375 return this; 7198 7376 }; … … 7395 7573 var _utils = jwplayer.utils; 7396 7574 var _isMobile = _utils.isMobile(); 7575 7576 var _allvideos = {}; 7397 7577 7398 7578 jwplayer.html5.mediavideo = function(model, container) { … … 7436 7616 _currentItem, 7437 7617 _interval, 7618 _delayedSeek, 7438 7619 _emptied = false, 7439 7620 _attached = false, … … 7487 7668 _video.src = item.file; 7488 7669 } 7670 _video.style.display = "block"; 7671 _video.volume = _model.volume / 100; 7672 _video.muted = _model.mute; 7489 7673 if (_isMobile) { 7490 if (item.image) { 7491 _video.poster = item.image; 7492 } 7493 _video.style.display = "block"; 7494 setTimeout(function() { 7495 _video.setAttribute("controls", "controls"); 7496 }, 100); 7674 _setControls(); 7497 7675 } 7498 7676 … … 7503 7681 item.start = 0; 7504 7682 } 7505 _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_LOADED); 7683 _delayedSeek = (item.start > 0) ? item.start : -1; 7684 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_LOADED); 7506 7685 if((!_isMobile && item.levels.length == 1) || !_emptied) { 7507 7686 _video.load(); … … 7510 7689 if (play) { 7511 7690 _setState(jwplayer.api.events.state.BUFFERING); 7512 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER, {7691 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER, { 7513 7692 bufferPercent: 0 7514 7693 }); … … 7523 7702 if (!_attached) return; 7524 7703 7525 if (_state != jwplayer.api.events.state.PLAYING) { 7526 _startInterval(); 7527 if (_bufferFull) { 7528 _setState(jwplayer.api.events.state.PLAYING); 7529 } else { 7530 _setState(jwplayer.api.events.state.BUFFERING); 7531 } 7532 _video.play(); 7533 } 7704 _startInterval(); 7705 if (_bufferFull) { 7706 _setState(jwplayer.api.events.state.PLAYING); 7707 } else { 7708 _setState(jwplayer.api.events.state.BUFFERING); 7709 } 7710 _video.play(); 7534 7711 } 7535 7712 … … 7550 7727 this.seek = function(position) { 7551 7728 if (!_attached) return; 7552 7553 if (!(_model.duration <= 0 || isNaN(_model.duration)) && 7554 !(_model.position <= 0 || isNaN(_model.position))) { 7555 _video.currentTime = position; 7556 _video.play(); 7729 if (!_start && _video.readyState > 0) { 7730 if (!(_model.duration <= 0 || isNaN(_model.duration)) && 7731 !(_model.position <= 0 || isNaN(_model.position))) { 7732 _video.currentTime = position; 7733 _video.play(); 7734 } 7735 } else { 7736 _delayedSeek = position; 7557 7737 } 7558 7738 } … … 7582 7762 _video.removeAttribute("src"); 7583 7763 } 7584 _video.removeAttribute("controls"); 7585 _video.removeAttribute("poster"); 7764 _hideControls(); 7586 7765 _utils.empty(_video); 7587 7766 _video.load(); … … 7607 7786 /** Resize the player. **/ 7608 7787 this.resize = function(width, height) { 7609 // _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_RESIZE, {7788 // _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_RESIZE, { 7610 7789 // fullscreen: _model.fullscreen, 7611 7790 // width: width, … … 7618 7797 if (!_isMobile) { 7619 7798 _video.volume = position / 100; 7620 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_VOLUME, {7799 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_VOLUME, { 7621 7800 volume: (position / 100) 7622 7801 }); … … 7629 7808 if (!_isMobile) { 7630 7809 _video.muted = state; 7631 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_MUTE, {7810 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_MUTE, { 7632 7811 mute: state 7633 7812 }); … … 7671 7850 function _handleMediaEvent(type, handler) { 7672 7851 return function(evt) { 7673 if (_ attached && _utils.exists(evt.target.parentNode)) {7852 if (_utils.exists(evt.target.parentNode)) { 7674 7853 handler(evt); 7675 7854 } … … 7679 7858 /** Initializes the HTML5 video and audio media provider **/ 7680 7859 function _init() { 7681 if (!_video) {7682 if (_container.tagName.toLowerCase() == "video") {7683 _video = _container;7684 } else {7685 _video = document.createElement("video");7686 }7687 }7688 7860 _state = jwplayer.api.events.state.IDLE; 7689 7861 7690 for (var event in _events) {7691 _video.addEventListener(event, _handleMediaEvent(event, _events[event]), true);7692 }7693 7862 _attached = true; 7863 7864 _video = _getVideoElement(); 7694 7865 7695 7866 _video.setAttribute("x-webkit-airplay", "allow"); … … 7702 7873 _video.id = _container.id; 7703 7874 } 7704 7705 _video.volume = _model.volume / 100; 7875 } 7876 7877 function _getVideoElement() { 7878 var vid; 7879 if (!_allvideos[_model.id]) { 7880 if (_container.tagName.toLowerCase() == "video") { 7881 vid = _container; 7882 } else { 7883 vid = document.createElement("video"); 7884 } 7885 for (var event in _events) { 7886 vid.addEventListener(event, _handleMediaEvent(event, _events[event]), true); 7887 } 7888 _allvideos[_model.id] = vid; 7889 } 7890 return _allvideos[_model.id]; 7706 7891 } 7707 7892 … … 7713 7898 } 7714 7899 7900 if (_isMobile) { 7901 switch (newstate) { 7902 case jwplayer.api.events.state.PLAYING: 7903 _setControls(); 7904 break; 7905 default: 7906 _hideControls(); 7907 break; 7908 } 7909 } 7910 7715 7911 if (_state != newstate) { 7716 7912 var oldstate = _state; 7717 7913 _model.state = _state = newstate; 7718 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_PLAYER_STATE, {7914 _sendEvent(jwplayer.api.events.JWPLAYER_PLAYER_STATE, { 7719 7915 oldstate: oldstate, 7720 7916 newstate: newstate … … 7731 7927 function _volumeHandler(event) { 7732 7928 var newVol = Math.round(_video.volume * 100); 7733 if (newVol != _model.volume) { 7734 _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_VOLUME, { 7735 volume: newVol 7736 }); 7737 } 7738 if (_video.muted != _model.mute) { 7739 _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_MUTE, { 7740 mute: _video.muted 7741 }); 7742 } 7929 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_VOLUME, { 7930 volume: newVol 7931 }, true); 7932 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_MUTE, { 7933 mute: _video.muted 7934 }, true); 7743 7935 } 7744 7936 7745 7937 /** Update the player progress **/ 7746 7938 function _progressHandler(event) { 7939 if (!_attached) return; 7940 7747 7941 var bufferPercent; 7748 7942 if (_utils.exists(event) && event.lengthComputable && event.total) { … … 7756 7950 7757 7951 if (_bufferFull === false && _state == jwplayer.api.events.state.BUFFERING) { 7758 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER_FULL);7952 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER_FULL); 7759 7953 _bufferFull = true; 7760 7954 } … … 7767 7961 if (_utils.exists(bufferPercent) && (bufferPercent > _model.buffer)) { 7768 7962 _model.buffer = Math.round(bufferPercent); 7769 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER, {7963 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER, { 7770 7964 bufferPercent: Math.round(bufferPercent) 7771 7965 }); … … 7777 7971 /** Update the player's position **/ 7778 7972 function _positionHandler(event) { 7973 if (!_attached) return; 7974 7779 7975 if (_utils.exists(event) && _utils.exists(event.target)) { 7780 if (!isNaN(event.target.duration) && (isNaN(_model.duration) || _model.duration < 1)) { 7781 if (event.target.duration == Infinity) { 7782 _model.duration = 0; 7783 } else { 7784 _model.duration = Math.round(event.target.duration * 10) / 10; 7976 if (_userDuration > 0) { 7977 if (!isNaN(event.target.duration) && (isNaN(_model.duration) || _model.duration < 1)) { 7978 if (event.target.duration == Infinity) { 7979 _model.duration = 0; 7980 } else { 7981 _model.duration = Math.round(event.target.duration * 10) / 10; 7982 } 7785 7983 } 7786 7984 } 7787 7985 if (!_start && _video.readyState > 0) { 7788 _video.style.display = "block";7789 7986 _setState(jwplayer.api.events.state.PLAYING); 7790 7987 } 7791 7988 7792 7989 if (_state == jwplayer.api.events.state.PLAYING) { 7793 if ( !_start && _video.readyState > 0) {7990 if (_video.readyState > 0 && (_delayedSeek > -1 || !_start)) { 7794 7991 _start = true; 7795 7992 try { 7796 if (_video.currentTime < _currentItem.start) { 7797 _video.currentTime = _currentItem.start; 7993 if (_video.currentTime != _delayedSeek && _delayedSeek > -1) { 7994 _video.currentTime = _delayedSeek; 7995 _delayedSeek = -1; 7798 7996 } 7799 7997 } catch (err) {} … … 7802 8000 } 7803 8001 _model.position = _model.duration > 0 ? (Math.round(event.target.currentTime * 10) / 10) : 0; 7804 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_TIME, {8002 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_TIME, { 7805 8003 position: _model.position, 7806 8004 duration: _model.duration … … 7819 8017 7820 8018 function _stateHandler(event) { 8019 if (!_attached) return; 8020 7821 8021 if (_states[event.type]) { 7822 8022 if (event.type == "ended") { … … 7829 8029 7830 8030 function _metaHandler(event) { 8031 if (!_attached) return; 7831 8032 var newDuration = Math.round(event.target.duration * 10) / 10; 7832 8033 var meta = { … … 7840 8041 } 7841 8042 } 7842 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_META, {8043 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_META, { 7843 8044 metadata: meta 7844 8045 }); … … 7846 8047 7847 8048 function _errorHandler(event) { 8049 if (!_attached) return; 8050 7848 8051 if (_state == jwplayer.api.events.state.IDLE) { 7849 8052 return; … … 7884 8087 message += _joinFiles(); 7885 8088 _error = true; 7886 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_ERROR, {8089 _sendEvent(jwplayer.api.events.JWPLAYER_ERROR, { 7887 8090 message: message 7888 8091 }); … … 7918 8121 7919 8122 function _complete() { 7920 if (_state != jwplayer.api.events.state.IDLE) {8123 if (_state == jwplayer.api.events.state.PLAYING) { 7921 8124 _stop(false); 7922 _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE); 8125 setTimeout(function() { 8126 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE); 8127 }, 10); 7923 8128 } 7924 8129 } … … 7928 8133 if (_model.fullscreen && !_video.webkitDisplayingFullscreen) { 7929 8134 //_model.fullscreen = _video.webkitDisplayingFullscreen; 7930 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_FULLSCREEN, {8135 _sendEvent(jwplayer.api.events.JWPLAYER_FULLSCREEN, { 7931 8136 fullscreen: false 7932 } );8137 },true); 7933 8138 } 7934 8139 } … … 7950 8155 levels.unshift(mp4); 7951 8156 } 8157 } 8158 } 8159 } 8160 8161 function _setControls() { 8162 if (_currentItem.image) { 8163 _video.poster = _currentItem.image; 8164 } 8165 setTimeout(function() { 8166 _video.setAttribute("controls", "controls"); 8167 }, 100); 8168 } 8169 8170 function _hideControls() { 8171 _video.removeAttribute("controls"); 8172 _video.removeAttribute("poster"); 8173 } 8174 8175 function _sendEvent(type, obj, alwaysSend) { 8176 if (_attached || alwaysSend) { 8177 if (obj) { 8178 _eventDispatcher.sendEvent(type, obj); 8179 } else { 8180 _eventDispatcher.sendEvent(type); 7952 8181 } 7953 8182 } … … 9379 9608 _api.jwStop = _controller.stop; 9380 9609 _api.jwSeek = _controller.seek; 9381 _api.jwPlaylistItem = _controller.item; 9610 _api.jwPlaylistItem = function(item) { 9611 if (_instreamPlayer) { 9612 if (_instreamPlayer.playlistClickable()) { 9613 _instreamPlayer.jwInstreamDestroy(); 9614 return _controller.item(item); 9615 } 9616 } else { 9617 return _controller.item(item); 9618 } 9619 } 9382 9620 _api.jwPlaylistNext = _controller.next; 9383 9621 _api.jwPlaylistPrev = _controller.prev; … … 9402 9640 } 9403 9641 9404 _api.jwGet Item= _statevarFactory('item');9642 _api.jwGetPlaylistIndex = _statevarFactory('item'); 9405 9643 _api.jwGetPosition = _statevarFactory('position'); 9406 9644 _api.jwGetDuration = _statevarFactory('duration'); … … 9425 9663 return _model.playlist; 9426 9664 }; 9427 _api.jwGetPlaylistIndex = _api.jwGetItem;9428 9665 9429 9666 _api.jwAddEventListener = _controller.addEventListener; … … 9449 9686 //InStream API 9450 9687 _api.jwLoadInstream = function(item, options) { 9451 _instreamPlayer = new jwplayer.html5.instream(item, options, _api, _model, _view, _controller); 9688 if (!_instreamPlayer) { 9689 _instreamPlayer = new jwplayer.html5.instream(_api, _model, _view, _controller); 9690 } 9691 setTimeout(function() { 9692 _instreamPlayer.load(item, options); 9693 }, 10); 9452 9694 } 9453 9695 _api.jwInstreamDestroy = function() { 9454 9696 if (_instreamPlayer) { 9455 9697 _instreamPlayer.jwInstreamDestroy(); 9456 _instreamPlayer = null;9457 9698 } 9458 9699 } -
branches/fl5_instream/js/src/events/jwplayer.events.eventdispatcher.js
r1858 r2047 76 76 /** Add an event listener for all events. **/ 77 77 this.removeGlobalListener = function(listener) { 78 if (! _globallisteners[type]) {78 if (!listener) { 79 79 return; 80 80 } -
branches/fl5_instream/js/src/html5/jwplayer.html5.api.js
r2043 r2047 51 51 _api.jwStop = _controller.stop; 52 52 _api.jwSeek = _controller.seek; 53 _api.jwPlaylistItem = _controller.item; 53 _api.jwPlaylistItem = function(item) { 54 if (_instreamPlayer) { 55 if (_instreamPlayer.playlistClickable()) { 56 _instreamPlayer.jwInstreamDestroy(); 57 return _controller.item(item); 58 } 59 } else { 60 return _controller.item(item); 61 } 62 } 54 63 _api.jwPlaylistNext = _controller.next; 55 64 _api.jwPlaylistPrev = _controller.prev; … … 74 83 } 75 84 76 _api.jwGet Item= _statevarFactory('item');85 _api.jwGetPlaylistIndex = _statevarFactory('item'); 77 86 _api.jwGetPosition = _statevarFactory('position'); 78 87 _api.jwGetDuration = _statevarFactory('duration'); … … 97 106 return _model.playlist; 98 107 }; 99 _api.jwGetPlaylistIndex = _api.jwGetItem;100 108 101 109 _api.jwAddEventListener = _controller.addEventListener; … … 121 129 //InStream API 122 130 _api.jwLoadInstream = function(item, options) { 123 _instreamPlayer = new jwplayer.html5.instream(item, options, _api, _model, _view, _controller); 131 if (!_instreamPlayer) { 132 _instreamPlayer = new jwplayer.html5.instream(_api, _model, _view, _controller); 133 } 134 setTimeout(function() { 135 _instreamPlayer.load(item, options); 136 }, 10); 124 137 } 125 138 _api.jwInstreamDestroy = function() { 126 139 if (_instreamPlayer) { 127 140 _instreamPlayer.jwInstreamDestroy(); 128 _instreamPlayer = null;129 141 } 130 142 } -
branches/fl5_instream/js/src/html5/jwplayer.html5.controlbar.js
r2030 r2047 879 879 _hide(_elements.muteButton); 880 880 _show(_elements.unmuteButton); 881 _hide(_elements.volumeSliderProgress); 881 882 } else { 882 883 _show(_elements.muteButton); 883 884 _hide(_elements.unmuteButton); 885 _show(_elements.volumeSliderProgress); 884 886 } 885 887 } -
branches/fl5_instream/js/src/html5/jwplayer.html5.controller.js
r2032 r2047 19 19 _preplay = false, 20 20 _interruptPlay = false, 21 _actionOnAttach, 21 22 _queuedEvents = [], 22 23 _ready = false; … … 88 89 function _play() { 89 90 try { 91 _actionOnAttach = _play; 90 92 if (!_preplay) { 91 93 _preplay = true; … … 94 96 if (_interruptPlay) { 95 97 _interruptPlay = false; 98 _actionOnAttach = null; 96 99 return; 97 100 } … … 110 113 } catch (err) { 111 114 _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_ERROR, err); 115 _actionOnAttach = null; 112 116 } 113 117 return false; … … 174 178 /** Stop playback and loading of the video. **/ 175 179 function _stop(clear) { 180 _actionOnAttach = null; 176 181 if (!_utils.exists(clear)) { 177 182 clear = true; … … 315 320 break; 316 321 } 322 _model.volume = volume; 317 323 return true; 318 324 } catch (err) { … … 446 452 function _attachMedia() { 447 453 try { 448 return _model.getMedia().attachMedia(); 454 var ret = _model.getMedia().attachMedia(); 455 if (typeof _actionOnAttach == "function") { 456 _actionOnAttach(); 457 } 449 458 } catch (err) { 450 459 return null; … … 460 469 461 470 function _completeHandler() { 471 _actionOnAttach = _completeHandler; 462 472 switch (_model.config.repeat.toUpperCase()) { 463 473 case jwplayer.html5.controller.repeatoptions.SINGLE: … … 519 529 this.playerReady = _playerReady; 520 530 this.detachMedia = _detachMedia; 521 this.attachMedia = _attachMedia; 531 this.attachMedia = _attachMedia; 532 this.beforePlay = function() { 533 return _preplay; 534 } 522 535 }; 523 536 })(jwplayer); -
branches/fl5_instream/js/src/html5/jwplayer.html5.display.js
r2021 r2047 314 314 return; 315 315 } 316 316 317 _lastState = state; 317 318 … … 342 343 switch (state) { 343 344 case jwplayer.api.events.state.BUFFERING: 344 if (_utils.is Mobile()) {345 if (_utils.isIPod()) { 345 346 _resetPoster(); 346 347 _hideDisplayIcon(); 347 348 } else { 348 if (_api.jwGetPlaylist()[_api.jwGet Item()].provider == "sound") {349 if (_api.jwGetPlaylist()[_api.jwGetPlaylistIndex()].provider == "sound") { 349 350 _showImage(); 350 351 } … … 359 360 break; 360 361 case jwplayer.api.events.state.PAUSED: 361 if (!_utils.is Mobile()) {362 if (_api.jwGetPlaylist()[_api.jwGet Item()].provider != "sound") {362 if (!_utils.isIPod()) { 363 if (_api.jwGetPlaylist()[_api.jwGetPlaylistIndex()].provider != "sound") { 363 364 _css(_display.display_image, { 364 365 background: "transparent no-repeat center center" … … 370 371 break; 371 372 case jwplayer.api.events.state.IDLE: 372 if (_api.jwGetPlaylist()[_api.jwGet Item()] && _api.jwGetPlaylist()[_api.jwGetItem()].image) {373 if (_api.jwGetPlaylist()[_api.jwGetPlaylistIndex()] && _api.jwGetPlaylist()[_api.jwGetPlaylistIndex()].image) { 373 374 _showImage(); 374 375 } else { … … 379 380 break; 380 381 default: 381 if (_api.jwGetPlaylist()[_api.jwGet Item()] && _api.jwGetPlaylist()[_api.jwGetItem()].provider == "sound") {382 if (_utils.is Mobile()) {382 if (_api.jwGetPlaylist()[_api.jwGetPlaylistIndex()] && _api.jwGetPlaylist()[_api.jwGetPlaylistIndex()].provider == "sound") { 383 if (_utils.isIPod()) { 383 384 _resetPoster(); 384 385 _showing = false; … … 401 402 402 403 function _showImage() { 403 if (_api.jwGetPlaylist()[_api.jwGet Item()] && _api.jwGetPlaylist()[_api.jwGetItem()].image) {404 if (_api.jwGetPlaylist()[_api.jwGetPlaylistIndex()] && _api.jwGetPlaylist()[_api.jwGetPlaylistIndex()].image) { 404 405 _css(_display.display_image, { 405 406 display: "block" 406 407 }); 407 _display.display_image.src = _utils.getAbsolutePath(_api.jwGetPlaylist()[_api.jwGet Item()].image);408 _display.display_image.src = _utils.getAbsolutePath(_api.jwGetPlaylist()[_api.jwGetPlaylistIndex()].image); 408 409 } 409 410 } -
branches/fl5_instream/js/src/html5/jwplayer.html5.instream.js
r2043 r2047 8 8 var _utils = jwplayer.utils; 9 9 10 jwplayer.html5.instream = function(item, options, api, model, view, controller) { 11 var _item = new jwplayer.html5.playlistitem(item), 12 _api = api, 13 _options = options, 14 _model = model, 15 _view = view, 16 _controller = controller, 17 _currentItem = _model.item, 18 _currentPlaylist = _model.playlist, 19 _video, _oldsrc, _oldsources, _oldpos, 20 _self = this, 21 _provider, _cbar, 10 jwplayer.html5.instream = function(api, model, view, controller) { 11 var _defaultOptions = { 12 controlbarseekable:"always", 13 controlbarpausable:true, 14 controlbarstoppable:true, 15 playlistclickable:true 16 }; 17 18 var _item, 19 _options, 20 _api=api, _model=model, _view=view, _controller=controller, 21 _video, _oldsrc, _oldsources, _oldpos, _oldstate, _olditem, 22 _provider, _cbar, _disp, _instreamMode = false, 23 _dispatcher, _instreamContainer, 24 _self = this; 25 26 27 /***************************************** 28 ***** Public instream API methods ***** 29 *****************************************/ 30 31 /** Load an instream item and initialize playback **/ 32 this.load = function(item, options) { 33 // Update the instream player's model 34 _copyModel(); 35 // Sets internal instream mode to true 36 _instreamMode = true; 37 // Instream playback options 38 _options = _utils.extend(_defaultOptions, options); 39 // Copy the playlist item passed in and make sure it's formatted as a proper playlist item 40 _item = jwplayer.html5.playlistitem(item); 41 // Create (or reuse) video media provider. No checks right now to make sure it's a valid playlist item (i.e. provider="video"). 42 _setupProvider(); 43 // Create the container in which the controls will be placed 44 _instreamContainer = document.createElement("div"); 45 _instreamContainer.id = _self.id + "_instream_container"; 46 // Get the video tag, and make sure the original player's provider stops broadcasting events (pseudo-lock...) 47 _video = _controller.detachMedia(); 48 // Store this to compare later (in case the main player switches to the next playlist item when we switch out of instream playback mode 49 _olditem = _model.playlist[_model.item]; 50 // Keep track of the original player state 51 _oldstate = _api.jwGetState(); 52 // If the player's currently playing, pause the video tag 53 if (_oldstate == jwplayer.api.events.state.BUFFERING || _oldstate == jwplayer.api.events.state.PLAYING) { 54 _video.pause(); 55 } 56 57 // Copy the video src/sources tags and store the current playback time 58 _oldsrc = _video.src; 59 _oldsources = _video.innerHTML; 60 _oldpos = _video.currentTime; 61 62 // Instream display component 63 _disp = new jwplayer.html5.display(_self, _utils.extend({},_model.plugins.config.display)); 64 _instreamContainer.appendChild(_disp.getDisplayElement()); 65 66 // Instream controlbar (if not iOS/Android) 67 if (!_utils.isMobile()) { 68 _cbar = new jwplayer.html5.controlbar(_self, _utils.extend({},_model.plugins.config.controlbar, {})); 69 _instreamContainer.appendChild(_cbar.getDisplayElement()); 70 } 71 72 // Show the instream layer 73 _view.setupInstream(_instreamContainer); 74 // Resize the instream components to the proper size 75 _resize(_model.plugins.config.display.width, _model.plugins.config.display.height); 76 // Load the instream item and begin playback 77 _provider.load(_item); 78 } 79 80 /** Stop the instream playback and revert the main player back to its original state **/ 81 this.jwInstreamDestroy = function(complete) { 82 if (!_instreamMode) return; 83 // We're not in instream mode anymore. 84 _instreamMode = false; 85 // Load the original item into our provider, which sets up the regular player's video tag 86 _provider.load(_olditem, false); 87 // We don't want the position interval to be running anymore 88 _provider.stop(false); 89 // We don't want the instream provider to be attached to the video tag anymore 90 _provider.detachMedia(); 91 // Return the view to its normal state 92 _view.destroyInstream(); 93 // Let listeners know the instream player has been destroyed, and why 94 _sendEvent(jwplayer.api.events.JWPLAYER_INSTREAM_DESTROYED, {reason:(complete ? "complete":"destroyed")}, true); 95 // Re-attach the controller 96 _controller.attachMedia(); 97 if (_oldstate == jwplayer.api.events.state.BUFFERING || _oldstate == jwplayer.api.events.state.PLAYING) { 98 // Model was already correct; just resume playback 99 _video.play(); 100 if (_model.playlist[_model.item] == _olditem) { 101 // We need to seek using the player's real provider, since the seek may have to be delayed 102 _model.getMedia().seek(_oldpos); 103 } 104 } 105 return; 106 }; 107 108 /** Forward any calls to add and remove events directly to our event dispatcher **/ 109 this.jwInstreamAddEventListener = function(type, listener) { 110 _dispatcher.addEventListener(type, listener); 111 } 112 this.jwInstreamRemoveEventListener = function(type, listener) { 113 _dispatcher.removeEventListener(type, listener); 114 } 115 116 /** Start instream playback **/ 117 this.jwInstreamPlay = function() { 118 if (!_instreamMode) return; 119 _provider.play(true); 120 } 121 122 /** Pause instream playback **/ 123 this.jwInstreamPause = function() { 124 if (!_instreamMode) return; 125 _provider.pause(true); 126 } 127 128 /** Seek to a point in instream media **/ 129 this.jwInstreamSeek = function(position) { 130 if (!_instreamMode) return; 131 _provider.seek(position); 132 } 133 134 /** Get the current instream state **/ 135 this.jwInstreamGetState = function() { 136 if (!_instreamMode) return undefined; 137 return _fakemodel.state; 138 } 139 140 /** Get the current instream playback position **/ 141 this.jwInstreamGetPosition = function() { 142 if (!_instreamMode) return undefined; 143 return _fakemodel.position; 144 } 145 146 /** Get the current instream media duration **/ 147 this.jwInstreamGetDuration = function() { 148 if (!_instreamMode) return undefined; 149 return _fakemodel.duration; 150 } 151 152 this.playlistClickable = function() { 153 return (!_instreamMode || _options.playlistclickable.toString().toLowerCase()=="true"); 154 } 155 156 157 /***************************** 158 ****** Private methods ****** 159 *****************************/ 160 161 function _init() { 162 // Initialize the instream player's model copied from main player's model 163 _fakemodel = new jwplayer.html5.model(this, _model.getMedia() ? _model.getMedia().getDisplayElement() : _model.container, _model); 164 // Create new event dispatcher 22 165 _dispatcher = new jwplayer.html5.eventdispatcher(); 23 24 25 function _init() { 26 var _thing = document.createElement("div"); 27 _thing.id = _self.id; 28 29 _controller.pause(); 30 _video = _controller.detachMedia(); 31 // _video.style.zIndex = 10; 32 33 34 _oldsrc = _video.src; 35 _oldsources = _video.getElementsByTagName("source"); 36 _oldpos = _video.currentPosition; 37 38 _view.setupInstream(_thing); 39 40 _setupProvider(); 41 42 _cbar = new jwplayer.html5.controlbar(_self, _utils.extend({},_model.plugins.config.controlbar, {position:"OVER"})); 43 44 _thing.appendChild(_cbar.getDisplayElement()); 45 46 47 _resize(_api.jwGetWidth(), _api.jwGetHeight()); 48 49 _provider.load(_item); 50 51 return; 52 }; 166 // Listen for player resize events 167 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_RESIZE, function(evt) { 168 _resize(evt.width, evt.height); 169 }); 170 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_FULLSCREEN, function(evt) { 171 _resize(evt.width, evt.height); 172 }); 173 } 174 175 function _copyModel() { 176 _fakemodel.mute = _model.mute; 177 _fakemodel.volume = _model.volume; 178 } 53 179 54 180 function _setupProvider() { 55 _provider = new jwplayer.html5.mediavideo(_model, _model.getMedia() ? _model.getMedia().getDisplayElement() : _model.container); 56 _provider.addGlobalListener( 57 function(evt) { 58 _dispatcher.sendEvent(evt.type, evt); 181 if (!_provider) { 182 _provider = new jwplayer.html5.mediavideo(_fakemodel, _model.getMedia() ? _model.getMedia().getDisplayElement() : _model.container); 183 _provider.addGlobalListener(_forward); 184 _provider.addEventListener(jwplayer.api.events.JWPLAYER_MEDIA_META, _metaHandler); 185 _provider.addEventListener(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE, _completeHandler); 186 } 187 _provider.attachMedia(); 188 } 189 190 /** Forward provider events to listeners **/ 191 function _forward(evt) { 192 if (_instreamMode) { 193 _sendEvent(evt.type, evt); 194 } 195 } 196 197 /** Handle the JWPLAYER_MEDIA_COMPLETE event **/ 198 function _completeHandler(evt) { 199 if (_instreamMode) { 200 setTimeout(function() { 201 _self.jwInstreamDestroy(true); 202 }, 10); 203 } 204 } 205 206 /** Handle the JWPLAYER_MEDIA_META event **/ 207 function _metaHandler(evt) { 208 // If we're getting video dimension metadata from the provider, allow the view to resize the media 209 if (evt.metadata.width && evt.metadata.height) { 210 _view.resizeMedia(); 211 } 212 } 213 214 function _sendEvent(type, data, forceSend) { 215 if (_instreamMode || forceSend) { 216 _dispatcher.sendEvent(type, data); 217 } 218 } 219 220 // Resize handler; resize the components. 221 function _resize(width, height) { 222 if (_cbar) { 223 var originalBar = _view.getComponentPosition('controlbar'); 224 _css(_cbar.getDisplayElement(), _utils.extend({}, originalBar, { 225 position: "absolute", 226 zIndex: 1001 227 })); 228 _cbar.resize(originalBar.width, originalBar.height); 229 } 230 if (_disp) { 231 var originalDisp = _view.getComponentPosition('display'); 232 _css(_disp.getDisplayElement(), _utils.extend({}, originalDisp, { 233 position: "absolute", 234 zIndex: 1000 235 })); 236 _disp.resize(originalDisp.width, originalDisp.height); 237 } 238 if (_view) { 239 _view.resizeMedia(); 240 } 241 } 242 243 244 /************************************** 245 ***** Duplicate main html5 api ***** 246 **************************************/ 247 248 this.jwPlay = function(state) { 249 if (_options.controlbarpausable.toString().toLowerCase()=="true") { 250 this.jwInstreamPlay(); 251 } 252 }; 253 254 this.jwPause = function(state) { 255 if (_options.controlbarpausable.toString().toLowerCase()=="true") { 256 this.jwInstreamPause(); 257 } 258 }; 259 260 this.jwStop = function() { 261 if (_options.controlbarstoppable.toString().toLowerCase()=="true") { 262 this.jwInstreamDestroy(); 263 } 264 }; 265 266 this.jwSeek = function(position) { 267 switch(_options.controlbarseekable.toLowerCase()) { 268 case "always": 269 this.jwInstreamSeek(position); 270 break; 271 case "backwards": 272 if (_fakemodel.position > position) { 273 this.jwInstreamSeek(position); 59 274 } 60 ); 61 _provider.addEventListener(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE, function(evt) { 62 _self.jwInstreamDestroy(); 63 }); 64 } 65 66 function _resize(width, height) { 67 _css(_cbar.getDisplayElement(), { 68 position: "absolute", 69 width: width, 70 height: height, 71 zIndex: 1000 72 }); 73 _cbar.resize(width, height); 74 } 75 76 this.jwInstreamAddEventListener = _dispatcher.addEventListener; 77 this.jwInstreamRemoveEventListener = _dispatcher.removeEventListener; 78 79 this.jwInstreamPlay = function() { 80 } 81 82 this.jwInstreamPause = function() { 83 } 84 85 this.jwInstreamSeek = function(position) { 86 } 87 88 89 this.jwInstreamGetState = function() { 90 } 91 92 this.jwInstreamGetPosition = function() { 93 } 94 95 this.jwInstreamGetDuration = function() { 96 } 97 98 this.jwInstreamDestroy = function() { 99 _video.pause(); 100 _video.src = _oldsrc; 101 for (var i=0; i < _oldsources.length; i++) { 102 _video.appendChild(_oldsources[i]); 103 } 104 _video.currentPosition = _oldpos; 105 _video.load(); 106 _view.destroyInstream(); 107 108 _controller.attachMedia(); 109 // _model.getMedia().load(_currentPlaylist[_currentItem]); 110 // _video.pause(); 111 //_utils.setOuterHTML(_video, _videoHTML); 112 } 113 114 115 /** Duplicate main html5 api **/ 116 this.skin = _api.skin; 117 118 this.jwPlay = function(state) {}; 119 this.jwPause = function(state) {}; 120 this.jwSeek = function(position) {}; 121 this.jwStop = function() {}; 122 this.jwGetItem = function() {}; 275 break; 276 } 277 }; 278 123 279 this.jwGetPosition = function() {}; 124 280 this.jwGetDuration = function() {}; 125 126 281 this.jwGetWidth = _api.jwGetWidth; 127 282 this.jwGetHeight = _api.jwGetHeight; 128 129 283 this.jwGetFullscreen = _api.jwGetFullscreen; 130 284 this.jwSetFullscreen = _api.jwSetFullscreen; 131 132 this.jwGetVolume = _api.jwGetVolume; 133 this.jwSetVolume = _api.jwSetVolume; 134 135 this.jwGetMute = _api.jwGetMute; 136 this.jwSetMute = _api.setMute; 137 138 this.jwGetState = function() {}; 139 140 this.jwGetPlaylist = function() { 141 return [_item]; 142 }; 143 this.jwGetPlaylistIndex = function() { 144 return 0; 145 }; 146 147 this.jwAddEventListener = function(type, handler) { 148 _dispatcher.addEventListener(type, handler); 149 } 150 this.jwRemoveEventListener = _dispatcher.removeEventListener; 151 285 this.jwGetVolume = function() { return _model.volume; }; 286 this.jwSetVolume = function(vol) { 287 _provider.volume(vol); 288 _api.jwSetVolume(vol); 289 } 290 this.jwGetMute = function() { return _model.mute; }; 291 this.jwSetMute = function(state) { 292 _provider.mute(state); 293 _api.jwSetMute(state); 294 } 295 this.jwGetState = function() { return _fakemodel.state; }; 296 this.jwGetPlaylist = function() { return [_item]; }; 297 this.jwGetPlaylistIndex = function() { return 0; }; 298 this.jwGetStretching = function() { return _model.config.stretching; }; 299 this.jwAddEventListener = function(type, handler) { _dispatcher.addEventListener(type, handler); }; 300 this.jwRemoveEventListener = function(type, handler) { _dispatcher.removeEventListener(type, handler); }; 301 302 this.skin = _api.skin; 152 303 this.id = _api.id; 153 304 154 305 _init(); 155 156 306 return this; 157 307 }; -
branches/fl5_instream/js/src/html5/jwplayer.html5.mediavideo.js
r2043 r2047 17 17 var _utils = jwplayer.utils; 18 18 var _isMobile = _utils.isMobile(); 19 20 var _allvideos = {}; 19 21 20 22 jwplayer.html5.mediavideo = function(model, container) { … … 58 60 _currentItem, 59 61 _interval, 62 _delayedSeek, 60 63 _emptied = false, 61 64 _attached = false, … … 109 112 _video.src = item.file; 110 113 } 114 _video.style.display = "block"; 115 _video.volume = _model.volume / 100; 116 _video.muted = _model.mute; 111 117 if (_isMobile) { 112 if (item.image) { 113 _video.poster = item.image; 114 } 115 _video.style.display = "block"; 116 setTimeout(function() { 117 _video.setAttribute("controls", "controls"); 118 }, 100); 118 _setControls(); 119 119 } 120 120 … … 125 125 item.start = 0; 126 126 } 127 _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_LOADED); 127 _delayedSeek = (item.start > 0) ? item.start : -1; 128 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_LOADED); 128 129 if((!_isMobile && item.levels.length == 1) || !_emptied) { 129 130 _video.load(); … … 132 133 if (play) { 133 134 _setState(jwplayer.api.events.state.BUFFERING); 134 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER, {135 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER, { 135 136 bufferPercent: 0 136 137 }); … … 145 146 if (!_attached) return; 146 147 147 if (_state != jwplayer.api.events.state.PLAYING) { 148 _startInterval(); 149 if (_bufferFull) { 150 _setState(jwplayer.api.events.state.PLAYING); 151 } else { 152 _setState(jwplayer.api.events.state.BUFFERING); 153 } 154 _video.play(); 155 } 148 _startInterval(); 149 if (_bufferFull) { 150 _setState(jwplayer.api.events.state.PLAYING); 151 } else { 152 _setState(jwplayer.api.events.state.BUFFERING); 153 } 154 _video.play(); 156 155 } 157 156 … … 172 171 this.seek = function(position) { 173 172 if (!_attached) return; 174 175 if (!(_model.duration <= 0 || isNaN(_model.duration)) && 176 !(_model.position <= 0 || isNaN(_model.position))) { 177 _video.currentTime = position; 178 _video.play(); 173 if (!_start && _video.readyState > 0) { 174 if (!(_model.duration <= 0 || isNaN(_model.duration)) && 175 !(_model.position <= 0 || isNaN(_model.position))) { 176 _video.currentTime = position; 177 _video.play(); 178 } 179 } else { 180 _delayedSeek = position; 179 181 } 180 182 } … … 204 206 _video.removeAttribute("src"); 205 207 } 206 _video.removeAttribute("controls"); 207 _video.removeAttribute("poster"); 208 _hideControls(); 208 209 _utils.empty(_video); 209 210 _video.load(); … … 229 230 /** Resize the player. **/ 230 231 this.resize = function(width, height) { 231 // _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_RESIZE, {232 // _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_RESIZE, { 232 233 // fullscreen: _model.fullscreen, 233 234 // width: width, … … 240 241 if (!_isMobile) { 241 242 _video.volume = position / 100; 242 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_VOLUME, {243 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_VOLUME, { 243 244 volume: (position / 100) 244 245 }); … … 251 252 if (!_isMobile) { 252 253 _video.muted = state; 253 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_MUTE, {254 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_MUTE, { 254 255 mute: state 255 256 }); … … 293 294 function _handleMediaEvent(type, handler) { 294 295 return function(evt) { 295 if (_ attached && _utils.exists(evt.target.parentNode)) {296 if (_utils.exists(evt.target.parentNode)) { 296 297 handler(evt); 297 298 } … … 301 302 /** Initializes the HTML5 video and audio media provider **/ 302 303 function _init() { 303 if (!_video) {304 if (_container.tagName.toLowerCase() == "video") {305 _video = _container;306 } else {307 _video = document.createElement("video");308 }309 }310 304 _state = jwplayer.api.events.state.IDLE; 311 305 312 for (var event in _events) {313 _video.addEventListener(event, _handleMediaEvent(event, _events[event]), true);314 }315 306 _attached = true; 307 308 _video = _getVideoElement(); 316 309 317 310 _video.setAttribute("x-webkit-airplay", "allow"); … … 324 317 _video.id = _container.id; 325 318 } 326 327 _video.volume = _model.volume / 100; 319 } 320 321 function _getVideoElement() { 322 var vid; 323 if (!_allvideos[_model.id]) { 324 if (_container.tagName.toLowerCase() == "video") { 325 vid = _container; 326 } else { 327 vid = document.createElement("video"); 328 } 329 for (var event in _events) { 330 vid.addEventListener(event, _handleMediaEvent(event, _events[event]), true); 331 } 332 _allvideos[_model.id] = vid; 333 } 334 return _allvideos[_model.id]; 328 335 } 329 336 … … 335 342 } 336 343 344 if (_isMobile) { 345 switch (newstate) { 346 case jwplayer.api.events.state.PLAYING: 347 _setControls(); 348 break; 349 default: 350 _hideControls(); 351 break; 352 } 353 } 354 337 355 if (_state != newstate) { 338 356 var oldstate = _state; 339 357 _model.state = _state = newstate; 340 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_PLAYER_STATE, {358 _sendEvent(jwplayer.api.events.JWPLAYER_PLAYER_STATE, { 341 359 oldstate: oldstate, 342 360 newstate: newstate … … 353 371 function _volumeHandler(event) { 354 372 var newVol = Math.round(_video.volume * 100); 355 if (newVol != _model.volume) { 356 _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_VOLUME, { 357 volume: newVol 358 }); 359 } 360 if (_video.muted != _model.mute) { 361 _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_MUTE, { 362 mute: _video.muted 363 }); 364 } 373 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_VOLUME, { 374 volume: newVol 375 }, true); 376 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_MUTE, { 377 mute: _video.muted 378 }, true); 365 379 } 366 380 367 381 /** Update the player progress **/ 368 382 function _progressHandler(event) { 383 if (!_attached) return; 384 369 385 var bufferPercent; 370 386 if (_utils.exists(event) && event.lengthComputable && event.total) { … … 378 394 379 395 if (_bufferFull === false && _state == jwplayer.api.events.state.BUFFERING) { 380 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER_FULL);396 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER_FULL); 381 397 _bufferFull = true; 382 398 } … … 389 405 if (_utils.exists(bufferPercent) && (bufferPercent > _model.buffer)) { 390 406 _model.buffer = Math.round(bufferPercent); 391 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER, {407 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_BUFFER, { 392 408 bufferPercent: Math.round(bufferPercent) 393 409 }); … … 399 415 /** Update the player's position **/ 400 416 function _positionHandler(event) { 417 if (!_attached) return; 418 401 419 if (_utils.exists(event) && _utils.exists(event.target)) { 402 if (!isNaN(event.target.duration) && (isNaN(_model.duration) || _model.duration < 1)) { 403 if (event.target.duration == Infinity) { 404 _model.duration = 0; 405 } else { 406 _model.duration = Math.round(event.target.duration * 10) / 10; 420 if (_userDuration > 0) { 421 if (!isNaN(event.target.duration) && (isNaN(_model.duration) || _model.duration < 1)) { 422 if (event.target.duration == Infinity) { 423 _model.duration = 0; 424 } else { 425 _model.duration = Math.round(event.target.duration * 10) / 10; 426 } 407 427 } 408 428 } 409 429 if (!_start && _video.readyState > 0) { 410 _video.style.display = "block";411 430 _setState(jwplayer.api.events.state.PLAYING); 412 431 } 413 432 414 433 if (_state == jwplayer.api.events.state.PLAYING) { 415 if ( !_start && _video.readyState > 0) {434 if (_video.readyState > 0 && (_delayedSeek > -1 || !_start)) { 416 435 _start = true; 417 436 try { 418 if (_video.currentTime < _currentItem.start) { 419 _video.currentTime = _currentItem.start; 437 if (_video.currentTime != _delayedSeek && _delayedSeek > -1) { 438 _video.currentTime = _delayedSeek; 439 _delayedSeek = -1; 420 440 } 421 441 } catch (err) {} … … 424 444 } 425 445 _model.position = _model.duration > 0 ? (Math.round(event.target.currentTime * 10) / 10) : 0; 426 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_TIME, {446 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_TIME, { 427 447 position: _model.position, 428 448 duration: _model.duration … … 441 461 442 462 function _stateHandler(event) { 463 if (!_attached) return; 464 443 465 if (_states[event.type]) { 444 466 if (event.type == "ended") { … … 451 473 452 474 function _metaHandler(event) { 475 if (!_attached) return; 453 476 var newDuration = Math.round(event.target.duration * 10) / 10; 454 477 var meta = { … … 462 485 } 463 486 } 464 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_META, {487 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_META, { 465 488 metadata: meta 466 489 }); … … 468 491 469 492 function _errorHandler(event) { 493 if (!_attached) return; 494 470 495 if (_state == jwplayer.api.events.state.IDLE) { 471 496 return; … … 506 531 message += _joinFiles(); 507 532 _error = true; 508 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_ERROR, {533 _sendEvent(jwplayer.api.events.JWPLAYER_ERROR, { 509 534 message: message 510 535 }); … … 540 565 541 566 function _complete() { 542 if (_state != jwplayer.api.events.state.IDLE) {567 if (_state == jwplayer.api.events.state.PLAYING) { 543 568 _stop(false); 544 _eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE); 569 setTimeout(function() { 570 _sendEvent(jwplayer.api.events.JWPLAYER_MEDIA_COMPLETE); 571 }, 10); 545 572 } 546 573 } … … 550 577 if (_model.fullscreen && !_video.webkitDisplayingFullscreen) { 551 578 //_model.fullscreen = _video.webkitDisplayingFullscreen; 552 _ eventDispatcher.sendEvent(jwplayer.api.events.JWPLAYER_FULLSCREEN, {579 _sendEvent(jwplayer.api.events.JWPLAYER_FULLSCREEN, { 553 580 fullscreen: false 554 } );581 },true); 555 582 } 556 583 } … … 576 603 } 577 604 605 function _setControls() { 606 if (_currentItem.image) { 607 _video.poster = _currentItem.image; 608 } 609 setTimeout(function() { 610 _video.setAttribute("controls", "controls"); 611 }, 100); 612 } 613 614 function _hideControls() { 615 _video.removeAttribute("controls"); 616 _video.removeAttribute("poster"); 617 } 618 619 function _sendEvent(type, obj, alwaysSend) { 620 if (_attached || alwaysSend) { 621 if (obj) { 622 _eventDispatcher.sendEvent(type, obj); 623 } else { 624 _eventDispatcher.sendEvent(type); 625 } 626 } 627 } 628 578 629 }; 579 630 })(jwplayer); -
branches/fl5_instream/js/src/html5/jwplayer.html5.view.js
r2043 r2047 23 23 var _falseFullscreen = false; 24 24 var _normalscreenWidth, _normalscreenHeight; 25 var _instremArea ;25 var _instremArea, _instreamMode; 26 26 27 27 function createWrapper() { … … 105 105 106 106 function _stateHandler(evt) { 107 _css(_box, { 108 display: (_model.getMedia() && _model.getMedia().hasChrome() && evt.newstate != jwplayer.api.events.state.IDLE) ? "none" : "block" 109 }); 107 if (_instreamMode) { return; } 108 109 if (_model.getMedia() && _model.getMedia().hasChrome()) { 110 _box.style.display = "block"; 111 } else { 112 switch (evt.newstate) { 113 case evt.newstate == jwplayer.api.events.state.PLAYING: 114 _box.style.display = "none"; 115 break; 116 default: 117 _box.style.display = "block"; 118 break; 119 } 120 } 110 121 } 111 122 … … 138 149 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_PLAYER_STATE, _stateHandler); 139 150 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_MEDIA_LOADED, _loadedHandler); 140 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_MEDIA_META, function( ) {151 _api.jwAddEventListener(jwplayer.api.events.JWPLAYER_MEDIA_META, function(evt) { 141 152 _resizeMedia(); 142 153 }); … … 315 326 } 316 327 317 function _resizeMedia() {328 var _resizeMedia = this.resizeMedia = function() { 318 329 if (!_utils.exists(_model.getMedia())) { 319 330 return; … … 361 372 } 362 373 363 function _getComponentPosition(pluginName) {374 var _getComponentPosition = this.getComponentPosition = function(pluginName) { 364 375 var plugincss = { 365 376 position: "absolute", … … 486 497 return false; 487 498 } 488 /// public function setupInstream(_instreamDisplay:DisplayObject, plugin:IPlugin):void {489 499 490 500 this.setupInstream = function(instreamDisplay) { … … 492 502 _box.style.display = "none"; 493 503 _instreamArea.appendChild(instreamDisplay); 494 }495 496 /// public function destroyInstream():void {504 _instreamMode = true; 505 } 506 497 507 var _destroyInstream = this.destroyInstream = function() { 498 508 _instreamArea.style.display = "none"; 509 _instreamArea.innerHTML = ""; 499 510 _box.style.display = "block"; 511 _instreamMode = false; 512 _resize(_model.width, _model.height); 500 513 } 501 514 }; 502 515 503 516 504 //TODO: Enum505 517 jwplayer.html5.view.positions = { 506 518 TOP: "TOP", -
branches/fl5_instream/js/src/jwplayer.js
r2043 r2047 11 11 var $jw = jwplayer; 12 12 13 jwplayer.version = '5.9.204 3';13 jwplayer.version = '5.9.2047'; 14 14 15 15 // "Shiv" method for older IE browsers; required for parsing media tags -
branches/fl5_instream/js/test/examples/instream.html
r2043 r2047 1 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 2 2 <html> 3 <head>4 <title>Instream API Example</title>5 <script type="text/javascript" src="../../bin-debug/jwplayer.js">3 <head> 4 <title>Instream API Example</title> 5 <script type="text/javascript" src="../../bin-debug/jwplayer.js"> 6 6 </script> 7 <script type="text/javascript" src="settings.js">7 <script type="text/javascript" src="settings.js"> 8 8 </script> 9 <style type="text/css"> 10 form { 11 margin-bottom: 15px; 12 overflow: hidden; 13 } 14 formset { 15 display:block; 16 float:left; 17 margin-right: 15px 18 } 19 </style> 20 </head> 21 <body> 22 <script type="text/javascript"> 9 <style type="text/css"> 10 form { 11 margin-bottom: 15px; 12 overflow: hidden; 13 } 14 15 formset { 16 display: block; 17 float: left; 18 margin-right: 15px 19 } 20 </style> 21 </head> 22 <body> 23 <script type="text/javascript"> 23 24 document.write("<h1>" + document.title + "</h1>"); 24 25 </script> 25 26 26 <form> 27 <formset> 28 <h3>Player Options</h3> 29 <label>Rendering mode</label> 30 <select id="mode"> 31 <option id="mode_flashonly" value="flashonly" selected="selected">Flash Only</option> 32 <option id="mode_html5only" value="html5only">HTML5 Only</option> 33 </select><br/> 34 <label>Instream Timing</label> 35 <select id="timing" onchange="return setupAll();"> 36 <option id="timing_beforeplay" value="beforeplay" selected="selected">onBeforePlay</option> 37 <option id="timing_button" value="button">Button click</option> 38 <option id="timing_time" value="time">At 5 seconds</option> 39 <option id="timing_complete" value="complete">onComplete</option> 40 </select><br/> 41 <label>Controlbar Position</label> 42 <select id="controlbar" onchange="return setupAll();"> 43 <option id="controlbar_over" value="over" selected="selected">Over</option> 44 <option id="controlbar_bottom" value="bottom">Bottom</option> 45 <option id="controlbar_top" value="top">Top</option> 46 </select><br/> 47 <label>Playlist Position</label> 48 <select id="playlist" onchange="return setupAll();"> 49 <option id="playlist_none" value="none" selected="selected">None</option> 50 <option id="playlist_right" value="right">Right</option> 51 </select><br/> 52 <label>Repeat</label> 53 <select id="repeat" onchange="return setupAll();"> 54 <option id="repeat_none" value="none" selected="selected">None</option> 55 <option id="repeat_list" value="list">List</option> 56 <option id="repeat_always" value="always">Always</option> 57 <option id="repeat_single" value="single">Single</option> 58 </select><br/> 59 <label>Skin</label> 60 <select id="skin" onchange="return setupAll();"> 61 <option id="skin_" value="" selected="selected">None</option> 62 <option id="skin_beelden" value="beelden">Beelden</option> 63 <option id="skin_classic" value="classic">Classic</option> 64 </select><br/> 65 <label>Stretching</label> 66 <select id="stretching" onchange="return setupAll();"> 67 <option id="stretching_uniform" value="uniform" selected="selected">Uniform</option> 68 <option id="stretching_exactfit" value="exactfit">Exactfit</option> 69 <option id="stretching_fill" value="fill">Fill</option> 70 <option id="stretching_none" value="none">None</option> 71 </select> 72 </formset> 73 <formset> 74 <h3>InStream Options</h3> 75 <label>Controlbar Seekable</label> 76 <select id="seekable" onchange="return setupAll();"> 77 <option id="seekable_always" value="always" selected="selected">Always</option> 78 <option id="seekable_never" value="never">Never</option> 79 <option id="seekable_backwards" value="backwards">Backwards</option> 80 </select><br/> 81 <label>Controlbar Pausable</label> 82 <select id="pausable" onchange="return setupAll();"> 83 <option id="pausable_true" value="true" selected="selected">True</option> 84 <option id="pausable_false" value="false">False</option> 85 </select><br/> 86 <label>Controlbar Stoppable</label> 87 <select id="stoppable" onchange="return setupAll();"> 88 <option id="stoppable_true" value="true" selected="selected">True</option> 89 <option id="stoppable_false" value="false">False</option> 90 </select><br/> 91 <label>Playlist Clickable</label> 92 <select id="playlist_clickable" onchange="return setupAll();"> 93 <option id="playlist_clickable_true" value="true" selected="selected">True</option> 94 <option id="playlist_clickable_false" value="false">False</option> 95 </select><br/> 96 <label>Autoload</label> 97 <select id="autoload" onchange="return setupAll();"> 98 <option id="autoload_false" value="false" selected="selected">False</option> 99 <option id="autoload_true" value="true">True</option> 100 </select><br/> 101 </formset> 102 <formset> 103 <h3>Log Events</h3> 104 <label>Action</label> 105 <select id="log"> 106 <option id="log_console" value="console" selected="selected">console.log</option> 107 <option id="log_alert" value="alert">alert</option> 108 </select><br/> 109 <label>Event</label> 110 <select id="events" multiple="multiple" size="10"> 111 <option value="onPlay">onPlay</option> 112 <option value="onPause">onPause</option> 113 <option value="onBuffer">onBuffer</option> 114 <option value="onIdle">onIdle</option> 115 <option value="onComplete">onComplete</option> 116 <option value="onTime">onTime</option> 117 <option value="onSeek">onSeek</option> 118 <option value="onMeta">onMeta</option> 119 <option value="onMute">onMute</option> 120 <option value="onVolume">onVolume</option> 121 <option value="onFullscreen">onFullscreen</option> 122 <option value="onError">onError</option> 123 <option value="onInstreamClick">onInstreamClick</option> 124 <option value="onInstreamDestroyed">onInstreamDestroyed</option> 125 </select> 126 </formset> 127 128 <button id="go" onclick="return setupAll();" style="float:left; clear:left">Update</button> 129 </form> 130 </p> 131 132 133 <hr/> 134 135 <div style="width:100%; height:300px; overflow:auto"> 136 <div style="float:left;"> 137 <div height="270" id="player" width="480"> 138 Player should replace this 139 </div> 140 </div> 141 <div style="float:left; margin-left: 15px;"> 142 <button id="instreamInit" onclick="initInstream();return false;" style="display:none">Click to initialize Instream</button> 143 <div id="instreamActions"> 144 <label>Instream Controls</label> 145 <button id="play" onclick="playInstream();return false;">Play</button> 146 <button id="pause" onclick="pauseInstream();return false;">Pause</button> 147 <button id="seek" onclick="seekInstream(10);return false;">seek(10)</button> 148 <button id="getters" onclick="updateGetters();return false;">Update Getters</button> 149 <button id="destroy" onclick="destroyInstream();return false">Destroy</button> 150 <br/> 151 <label>State:</label><span id="state">IDLE</span><br/> 152 <label>Position:</label><span id="position">0.0</span><br/> 153 <label>Duration:</label><span id="duration">0.0</span> 154 </div> 155 </div> 156 </div> 157 <script type="text/javascript"> 27 <form><formset> 28 <h3>Player Options</h3> 29 <label>Rendering mode</label> <select id="mode"> 30 <option id="mode_flash" value="flash" selected="selected">Flash 31 -> HTML5</option> 32 <option id="mode_html5" value="html5">HTML5 -> Flash</option> 33 </select><br /> 34 <label>Instream Timing</label> <select id="timing" 35 onchange="return setupAll();"> 36 <option id="timing_beforeplay" value="beforeplay" selected="selected">onBeforePlay</option> 37 <option id="timing_button" value="button">Button click</option> 38 <option id="timing_time" value="time">At 5 seconds</option> 39 <option id="timing_complete" value="complete">onComplete</option> 40 </select><br /> 41 <label>Controlbar Position</label> <select id="controlbar" 42 onchange="return setupAll();"> 43 <option id="controlbar_over" value="over" selected="selected">Over</option> 44 <option id="controlbar_bottom" value="bottom">Bottom</option> 45 <option id="controlbar_top" value="top">Top</option> 46 </select><br /> 47 <label>Playlist Position</label> <select id="playlist" 48 onchange="return setupAll();"> 49 <option id="playlist_none" value="none" selected="selected">None</option> 50 <option id="playlist_right" value="right">Right</option> 51 </select><br /> 52 <label>Repeat</label> <select id="repeat" onchange="return setupAll();"> 53 <option id="repeat_none" value="none" selected="selected">None</option> 54 <option id="repeat_list" value="list">List</option> 55 <option id="repeat_always" value="always">Always</option> 56 <option id="repeat_single" value="single">Single</option> 57 </select><br /> 58 <label>Skin</label> <select id="skin" onchange="return setupAll();"> 59 <option id="skin_" value="" selected="selected">None</option> 60 <option id="skin_beelden" value="beelden">Beelden</option> 61 <option id="skin_classic" value="classic">Classic</option> 62 </select><br /> 63 <label>Stretching</label> <select id="stretching" 64 onchange="return setupAll();"> 65 <option id="stretching_uniform" value="uniform" selected="selected">Uniform</option> 66 <option id="stretching_exactfit" value="exactfit">Exactfit</option> 67 <option id="stretching_fill" value="fill">Fill</option> 68 <option id="stretching_none" value="none">None</option> 69 </select> </formset> <formset> 70 <h3>InStream Options</h3> 71 <label>Controlbar Seekable</label> <select id="seekable" 72 onchange="return setupAll();"> 73 <option id="seekable_always" value="always" selected="selected">Always</option> 74 <option id="seekable_never" value="never">Never</option> 75 <option id="seekable_backwards" value="backwards">Backwards</option> 76 </select><br /> 77 <label>Controlbar Pausable</label> <select id="controlbarpausable" 78 onchange="return setupAll();"> 79 <option id="controlbarpausable_true" value="true" selected="selected">True</option> 80 <option id="controlbarpausable_false" value="false">False</option> 81 </select><br /> 82 <label>Controlbar Stoppable</label> <select id="controlbarstoppable" 83 onchange="return setupAll();"> 84 <option id="controlbarstoppable_true" value="true" selected="selected">True</option> 85 <option id="controlbarstoppable_false" value="false">False</option> 86 </select><br /> 87 <label>Playlist Clickable</label> <select id="playlistclickable" 88 onchange="return setupAll();"> 89 <option id="playlistclickable_true" value="true" selected="selected">True</option> 90 <option id="playlistclickable_false" value="false">False</option> 91 </select><br /> 92 <label>Autoload</label> <select id="autoload" 93 onchange="return setupAll();"> 94 <option id="autoload_false" value="false" selected="selected">False</option> 95 <option id="autoload_true" value="true">True</option> 96 </select><br /> 97 </formset> <formset> 98 <h3>Log Events</h3> 99 <label>Action</label> <select id="log"> 100 <option id="log_console" value="console" selected="selected">console.log</option> 101 <option id="log_alert" value="alert">alert</option> 102 </select><br /> 103 <label>Event</label> <select id="events" multiple="multiple" size="10"> 104 <option id="events_onPlay" value="onPlay">onPlay</option> 105 <option id="events_onPause" value="onPause">onPause</option> 106 <option id="events_onBuffer" value="onBuffer">onBuffer</option> 107 <option id="events_onIdle" value="onIdle">onIdle</option> 108 <option id="events_onComplete" value="onComplete">onComplete</option> 109 <option id="events_onTime" value="onTime">onTime</option> 110 <option id="events_onSeek" value="onSeek">onSeek</option> 111 <option id="events_onMeta" value="onMeta">onMeta</option> 112 <option id="events_onMute" value="onMute">onMute</option> 113 <option id="events_onVolume" value="onVolume">onVolume</option> 114 <option id="events_onFullscreen" value="onFullscreen">onFullscreen</option> 115 <option id="events_onError" value="onError">onError</option> 116 <option id="events_onInstreamClick" value="onInstreamClick">onInstreamClick</option> 117 <option id="events_onInstreamDestroyed" value="onInstreamDestroyed">onInstreamDestroyed</option> 118 </select> </formset> 119 120 <button id="go" onclick="return setupAll();" 121 style="float: left; clear: left">Update</button> 122 </form> 123 </p> 124 125 126 <hr /> 127 128 <div style="width: 100%; height: 300px; overflow: auto"> 129 <div style="float: left;"> 130 <div height="270" id="player" width="480">Player should replace 131 this</div> 132 </div> 133 <div style="float: left; margin-left: 15px;"> 134 <button id="instreamInit" onclick="initInstream();return false;" 135 style="display: none">Click to initialize Instream</button> 136 <div id="instreamActions"><label>Instream Controls</label> 137 <button id="play" onclick="playInstream();return false;">Play</button> 138 <button id="pause" onclick="pauseInstream();return false;">Pause</button> 139 <button id="seek" onclick="seekInstream(10);return false;">seek(10)</button> 140 <button id="getters" onclick="updateGetters();return false;">Update 141 Getters</button> 142 <button id="destroy" onclick="destroyInstream();return false">Destroy</button> 143 <br /> 144 <label>State:</label><span id="state">IDLE</span><br /> 145 <label>Position:</label><span id="position">0.0</span><br /> 146 <label>Duration:</label><span id="duration">0.0</span></div> 147 </div> 148 </div> 149 <script type="text/javascript"> 158 150 var player = null; 159 151 var instream = null; … … 171 163 instreamOptions = { 172 164 controlbarseekable: document.getElementById('seekable').value, 173 controlbarpausable: document.getElementById(' pausable').value,174 controlbarstoppable: document.getElementById(' stoppable').value,175 playlistclickable: document.getElementById('playlist _clickable').value,165 controlbarpausable: document.getElementById('controlbarpausable').value, 166 controlbarstoppable: document.getElementById('controlbarstoppable').value, 167 playlistclickable: document.getElementById('playlistclickable').value, 176 168 autoload: document.getElementById('autoload').value 177 169 }; … … 241 233 setupBlock.skin = "../../../../../tags/skins/" + skin + "/" + skin + ".zip"; 242 234 } 243 235 236 if (player) { 237 player.remove(); 238 } 244 239 player = jwplayer("player").setup(setupBlock); 245 240 return false; … … 304 299 305 300 301 function setDefaultEvents() { 302 var selectedEvents = getVariable("events").split(','); 303 for (var i=0; i<selectedEvents.length; i++) { 304 var opt = document.getElementById("events_"+selectedEvents[i]); 305 if (opt) { 306 opt.selected = true; 307 } 308 } 309 } 310 306 311 function setupEvents() { 307 312 if (!instream) return; 313 314 var allOptions = document.getElementById("events").options; 308 315 309 var allOptions = document.getElementById("events").options;310 316 for (var i=0; i < allOptions.length; i++) { 311 317 var option = allOptions[i]; … … 326 332 } 327 333 334 function getVariable(name) { 335 var regex = new RegExp(name+"=([\\w\\,]+)"); 336 var match = window.location.href.match(regex); 337 if (match && match.length > 1) { 338 return match[1]; 339 } else { 340 return ""; 341 } 342 } 343 328 344 function setDefault(name) { 329 var regex = new RegExp(name+"=(\\w+)"); 330 var val = window.location.href.match(regex); 331 if (val && val.length==2) { 332 document.getElementById(name+"_"+val[1]).selected = true; 333 } 334 } 345 var val = getVariable(name); 346 if (val) { 347 document.getElementById(name+"_"+val).selected = true; 348 } 349 } 335 350 336 351 setDefault("timing"); … … 343 358 344 359 setDefault("seekable"); 345 setDefault(" pausable");346 setDefault(" stoppable");347 setDefault("playlist _clickable");360 setDefault("controlbarpausable"); 361 setDefault("controlbarstoppable"); 362 setDefault("playlistclickable"); 348 363 setDefault("autoload"); 364 setDefaultEvents(); 349 365 350 366 setupAll(); 351 367 </script> 352 353 <h3>HTML code</h3>354 </body>368 369 <h3>HTML code</h3> 370 </body> 355 371 </html> -
branches/fl5_instream/js/test/examples/settings.js
r1831 r2047 24 24 html5only: [{type:'html5'}], 25 25 flashhtml5: [{type:'flash',src:'../../../player.swf'},{type:'html5'}], 26 html5flash: [{type:'html5'},{type:'flash',src:'../../../player.swf'}], 26 flash: [{type:'flash',src:'../../../player.swf'},{type:'html5'}], 27 html5: [{type:'html5'},{type:'flash',src:'../../../player.swf'}], 27 28 standard: [{type:'flash',src:'../../../player.swf'},{type:'html5'},{type:'download'}] 28 29 } -
branches/fl5_instream/src/com/longtailvideo/jwplayer/player/PlayerVersion.as
r2043 r2047 3 3 4 4 public class PlayerVersion { 5 protected static var _version:String = '5.9.204 3';5 protected static var _version:String = '5.9.2047'; 6 6 7 7 public static function get version():String {
Note: See TracChangeset
for help on using the changeset viewer.
