- Timestamp:
- 10/21/09 16:22:59 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/fl5/src/com/longtailvideo/jwplayer/media/YouTubeMediaProvider.as
r501 r511 26 26 /** connection from the YT proxy. **/ 27 27 private var inbound:LocalConnection; 28 /** Save that the meta has been sent. **/29 private var metasent:Boolean;30 28 /** Save that a load call has been sent. **/ 31 29 private var loading:Boolean; 32 30 /** Save the connection state. **/ 33 31 private var connected:Boolean; 34 /** URL of a custom youtube swf. **/35 private var location:String;36 32 37 33 38 34 /** Setup YouTube connections and load proxy. **/ 39 public function YouTubeMediaProvider(){ 40 } 35 public function YouTubeMediaProvider() { 36 } 37 41 38 42 39 public override function initializeMediaProvider(cfg:PlayerConfig):void { … … 44 41 _provider = 'youtube'; 45 42 Security.allowDomain('*'); 46 var url:String = RootReference.root.loaderInfo.url;47 if (url.indexOf('http://') == 0) {48 unique = Math.random().toString().substr(2);49 var str:String = url.substr(0, url.indexOf('.swf'));50 location = str.substr(0, str.lastIndexOf('/') + 1) + 'yt.swf?unique=' + unique;51 } else {52 unique = '1';53 location = 'yt.swf';54 }55 43 outgoing = new LocalConnection(); 56 44 outgoing.allowDomain('*'); … … 61 49 inbound.allowInsecureDomain('*'); 62 50 inbound.addEventListener(StatusEvent.STATUS, onLocalConnectionStatusChange); 63 //inbound.addEventListener(AsyncErrorEvent.ASYNC_ERROR,errorHandler);64 51 inbound.client = this; 65 52 loader = new Loader(); … … 94 81 95 82 83 /** Get the location of yt.swf. **/ 84 private function getLocation():String { 85 var loc:String; 86 var url:String = RootReference.stage.loaderInfo.url; 87 if (url.indexOf('http://') == 0) { 88 unique = Math.random().toString().substr(2); 89 loc = url.substr(0, url.indexOf('.swf')); 90 loc = loc.substr(0, loc.lastIndexOf('/') + 1) + 'yt.swf?unique=' + unique; 91 } else { 92 unique = '1'; 93 loc = 'yt.swf'; 94 } 95 return loc; 96 } 97 98 96 99 /** Load the YouTube movie. **/ 97 100 override public function load(itm:PlaylistItem):void { … … 102 105 if (outgoing) { 103 106 var gid:String = getID(_item.file); 107 outgoing.send('AS3_' + unique, "loadVideoById", gid, _item.start); 104 108 resize(_config.width, _config.width / 4 * 3); 105 outgoing.send('AS3_' + unique, "loadVideoById", gid, _item.start);106 109 media = loader; 107 110 } 108 111 } else { 112 loader.load(new URLRequest(getLocation())); 109 113 inbound.connect('AS2_' + unique); 110 loader.load(new URLRequest(location)); 111 } 112 _config.mute == true ? setVolume(0) : setVolume(_config.volume); 113 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_BUFFER, {percentage: 0}); 114 setState(PlayerState.BUFFERING); 114 } 115 115 } 116 116 … … 132 132 /** SWF loaded; add it to the tree **/ 133 133 public function onSwfLoadComplete():void { 134 _config.mute == true ? setVolume(0) : setVolume(_config.volume);135 134 connected = true; 136 135 if (loading) { … … 147 146 148 147 /** Catch youtube errors. **/ 149 public function onError(erc:String):void { 150 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_ERROR, {message: "YouTube error (video not found?):\n" + _item.file}); 148 public function onError(erc:Number):void { 151 149 stop(); 150 var msg:String = 'Video not found or deleted: ' + getID(item['file']); 151 if (erc == 101 || erc == 150) { 152 msg = 'Embedding this video is disabled by its owner.'; 153 } 154 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_ERROR, {message: msg}); 152 155 } 153 156 … … 173 176 case 3: 174 177 setState(PlayerState.BUFFERING); 175 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_BUFFER, {percentage: 0});176 178 break; 177 179 } … … 181 183 /** Catch Youtube load changes **/ 182 184 public function onLoadChange(ldd:Number, ttl:Number, off:Number):void { 183 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_LOADED, {loaded: ldd, total: ttl, offset: off}); 185 //sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_LOADED, {loaded: ldd, total: ttl, offset: off}); 186 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_LOADED); 187 _config.mute == true ? setVolume(0) : setVolume(_config.volume); 188 setState(PlayerState.BUFFERING); 189 sendBufferEvent(0); 184 190 } 185 191 … … 187 193 /** Catch Youtube _position changes **/ 188 194 public function onTimeChange(pos:Number, dur:Number):void { 189 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_TIME, {_position: pos, duration: dur}); 190 if (!metasent) { 191 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_META, {width: 320, height: 240, duration: dur}); 192 metasent = true; 195 if (state != PlayerState.PLAYING) { 196 setState(PlayerState.PLAYING); 197 } 198 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_TIME, {position: pos, duration: dur}); 199 if (item.duration <= 0) { 200 item.duration = dur; 193 201 } 194 202 } … … 210 218 /** Destroy the youtube video. **/ 211 219 override public function stop():void { 212 metasent = false; 213 outgoing.send('AS3_' + unique, "stopVideo"); 220 if (connected) { 221 outgoing.send('AS3_' + unique, "stopVideo"); 222 } else { 223 loading = false; 224 } 214 225 super.stop(); 215 226 }
Note: See TracChangeset
for help on using the changeset viewer.
