Changeset 851
- Timestamp:
- 02/24/10 15:09:55 (3 years ago)
- Location:
- branches/plugins/hd
- Files:
-
- 2 edited
-
bin-release/hd.swf (modified) (previous)
-
src/com/longtailvideo/plugins/hd/HD.as (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/plugins/hd/src/com/longtailvideo/plugins/hd/HD.as
r830 r851 1 1 2 2 package com.longtailvideo.plugins.hd { 3 3 4 4 import com.longtailvideo.jwplayer.events.MediaEvent; 5 5 import com.longtailvideo.jwplayer.events.PlaylistEvent; 6 import com.longtailvideo.jwplayer.model.IPlaylist; 7 import com.longtailvideo.jwplayer.model.PlaylistItem; 6 8 import com.longtailvideo.jwplayer.player.IPlayer; 7 9 import com.longtailvideo.jwplayer.player.PlayerState; … … 9 11 import com.longtailvideo.jwplayer.plugins.PluginConfig; 10 12 import com.longtailvideo.jwplayer.utils.Configger; 11 import com.longtailvideo.jwplayer.utils.Logger;12 13 13 14 import flash.display.DisplayObject; 14 15 import flash.display.MovieClip; 15 16 import flash.events.Event; 16 17 17 18 18 19 /** 19 20 * HD Plugin; implements an HD toggle. 20 21 **/ 21 22 public class HD extends MovieClip implements IPlugin { 22 23 23 24 [Embed(source="../../../../../assets/controlbar.png")] 24 25 private const ControlbarIcon:Class; 25 26 [Embed(source="../../../../../assets/dock.png")] 26 27 private const DockIcon:Class; 27 28 28 29 /** Reference to the player. **/ 29 30 private var _player:IPlayer; … … 34 35 /** Reference to the clip on stage. **/ 35 36 private var _icon:DisplayObject; 36 /** reference to the original file. **/37 private var _original:String;38 37 /** The current playlist item **/ 39 private var _currentI ndex:Number;38 private var _currentItem:PlaylistItem; 40 39 /** The current position inside a video. **/ 41 40 private var _position:Number = 0; 42 43 41 42 44 43 /** Constructor; nothing going on. **/ 45 44 public function HD():void { 46 45 } 47 48 46 47 49 48 /** The initialize call is invoked by the player. **/ 50 49 public function initPlugin(player:IPlayer, cfg:PluginConfig):void { … … 57 56 } 58 57 _player.addEventListener(MediaEvent.JWPLAYER_MEDIA_TIME, timeHandler); 59 _player.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_ITEM, item Locker);58 _player.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_ITEM, itemHandler); 60 59 if (config.state) { 61 60 config.file = config.file; … … 78 77 setUI(); 79 78 } 80 81 79 80 82 81 /** Upon resize, check for fullscreen switches. Switch the state if so. **/ 83 82 public function resize(width:Number, height:Number):void { 84 if (config.fullscreen && (_player.fullscreen != _player.state && _player.state != PlayerState.IDLE)) {83 if (config.fullscreen && (_player.fullscreen != config.state && _player.state != PlayerState.IDLE)) { 85 84 clickHandler(); 86 85 } 87 86 } 88 87 89 88 90 89 public function get config():PluginConfig { … … 92 91 } 93 92 94 93 95 94 public function get id():String { 96 95 return _config.id; 97 96 } 98 99 97 98 100 99 /** Save the position inside a video. **/ 101 100 private function timeHandler(evt:MediaEvent):void { 102 101 _position = evt.position; 103 102 } 104 105 103 106 104 /** HD _button is clicked, so change the video. **/ 107 105 private function clickHandler(evt:Event=null):void { … … 111 109 setUI(); 112 110 } 113 114 115 /** Locks the player and updates the current item **/ 116 private function itemLocker(evt:PlaylistEvent):void { 117 if (_currentIndex != _player.playlist.currentIndex) { 118 if (_original) { 119 _player.playlist.getItemAt(_currentIndex).file = _original; 120 } 121 _currentIndex = _player.playlist.currentIndex; 122 _original = _player.playlist.getItemAt(_currentIndex).file; 123 _position = 0; 124 _player.lock(this, itemHandler); 125 } 126 } 127 128 129 /** Updates the playlist with either the HD or default video. **/ 130 private function itemHandler():void { 131 var updated:Boolean; 132 133 if (config.state == false && _player.playlist.currentItem.file != _original) { 134 _player.playlist.currentItem.file = _original; 135 updated = true; 136 Logger.log("Switching to original"); 137 } else if (config.state == true && _player.playlist.currentItem.file != config.file) { 138 _player.playlist.currentItem.file = config.file; 139 updated = true; 140 Logger.log("Switching to HD"); 141 } 142 143 if (updated) { 144 _player.load(_player.playlist.currentItem); 145 _player.play(); 146 _player.seek(_position); 147 } 148 149 if (_player.locked) { 150 _player.unlock(this); 151 } 152 } 153 154 111 155 112 /** Set the HD _button state. **/ 156 113 private function setUI():void { 157 if (config.state == false) { 114 if (config.file || (_currentItem && _currentItem.hasOwnProperty('hd.file'))) { 115 _button.field.alpha = 1; 116 if (config.state == false) { 117 if (_button) { 118 _button.field.text = 'is off'; 119 _icon.alpha = 1; 120 } else { 121 _icon.alpha = 0.3; 122 } 123 } else { 124 _icon.alpha = 1; 125 if (_button) { 126 _button.field.text = 'is on'; 127 } 128 } 129 } else { 130 _icon.alpha = 0.5; 158 131 if (_button) { 159 _button.field.text = 'is off'; 160 } else { 161 _icon.alpha = 0.3; 162 } 163 } else { 164 if (_button) { 165 _button.field.text = 'is on'; 166 } else { 167 _icon.alpha = 1; 168 } 169 } 132 _button.field.text = 'not avail'; 133 _button.field.alpha = 0.5; 134 } 135 } 136 } 137 138 /** Updates the playlist with either the HD or default video. **/ 139 private function itemHandler(evt:Event=null):void { 140 if (_currentItem != _player.playlist.currentItem) { 141 _currentItem = _player.playlist.currentItem; 142 } 143 144 var swapFile:String = stateFile(); 145 if (swapFile) { 146 if (_currentItem.file != swapFile) { 147 swap(swapFile); 148 } 149 } 150 setUI(); 151 152 } 153 154 155 /** Switch the currently playing file with a new one. **/ 156 private function swap(newFile:String):void { 157 var newList:Array = playlistToArray(_player.playlist); 158 var newItem:PlaylistItem = newList[_player.playlist.currentIndex] as PlaylistItem; 159 if (!newItem.hasOwnProperty('hd.originalfile')) { 160 newItem['hd.originalfile'] = newItem.file; 161 } 162 newItem.file = newFile; 163 164 // Load a new playlist instead of changing the item's file property. 165 // This is necessary due to a bug in 5.0 that doesn't load a new file if the PlaylistItem object doesn't change. 166 _player.load(newList); 167 _player.play(); 168 _player.seek(_position); 169 } 170 171 /** Which file to play, based on the current state **/ 172 private function stateFile():String { 173 if (config.state) { 174 if (_currentItem.hasOwnProperty('hd.file')) { 175 return _currentItem['hd.file']; 176 } else if (config.hasOwnProperty('file')) { 177 return config['file']; 178 } else { 179 return ''; 180 } 181 } else { 182 if (_currentItem.hasOwnProperty('hd.originalfile')) { 183 return _currentItem['hd.originalfile']; 184 } else if (_currentItem.hasOwnProperty('hd.file') || config.hasOwnProperty('file')) { 185 return _currentItem.file; 186 } else { 187 return ''; 188 } 189 } 190 } 191 192 /** Clone a playlist's items and put everything in an array **/ 193 private function playlistToArray(source:IPlaylist):Array { 194 var playlistContents:Array = []; 195 for (var i:Number = 0; i < source.length; i++) { 196 playlistContents.push(clonePlaylistItem(source.getItemAt(i))); 197 } 198 return playlistContents; 199 } 200 201 /** Create a copy of a PlaylistItem **/ 202 private function clonePlaylistItem(source:PlaylistItem):PlaylistItem { 203 var newItem:PlaylistItem = new PlaylistItem(source); 204 newItem.author = source.author; 205 newItem.date = source.date; 206 newItem.description = source.description; 207 newItem.duration = source.duration; 208 newItem.file = source.file; 209 newItem.image = source.image; 210 newItem.link = source.link; 211 newItem.mediaid = source.mediaid; 212 newItem.provider = source.provider; 213 newItem.start = source.start; 214 newItem.tags = source.tags; 215 newItem.title = source.title; 216 return newItem; 170 217 } 171 218 }
Note: See TracChangeset
for help on using the changeset viewer.
