- Timestamp:
- 12/11/09 14:59:21 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/fl5/src/com/longtailvideo/jwplayer/media/RTMPMediaProvider.as
r642 r747 14 14 import com.longtailvideo.jwplayer.utils.NetClient; 15 15 import com.longtailvideo.jwplayer.utils.TEA; 16 16 17 17 import flash.events.*; 18 18 import flash.media.*; … … 40 40 /** Save that a file is _unpublished. **/ 41 41 protected var _unpublished:Boolean; 42 42 /** Whether the buffer has filled **/ 43 private var _bufferFull:Boolean; 43 44 44 45 public function RTMPMediaProvider() { … … 92 93 _item = itm; 93 94 _position = 0; 95 _bufferFull = false; 94 96 setState(PlayerState.BUFFERING); 95 97 sendBufferEvent(0); … … 143 145 } 144 146 147 148 /** Determines if the stream is a live stream **/ 149 private function get livestream():Boolean { 150 return item.duration == 0; 151 } 145 152 146 153 /** Pause playback. **/ … … 148 155 _stream.pause(); 149 156 clearInterval(_positionInterval); 157 _positionInterval = undefined; 150 158 super.pause(); 151 159 if (_started && item.duration == 0) { … … 157 165 /** Resume playing. **/ 158 166 override public function play():void { 159 _stream.resume(); 160 _positionInterval = setInterval(positionInterval, 100); 167 if (!(livestream && _started)) { 168 _stream.resume(); 169 } 170 if (!_positionInterval) { 171 _positionInterval = setInterval(positionInterval, 100); 172 } 161 173 super.play(); 162 174 } … … 166 178 protected function positionInterval():void { 167 179 _position = Math.round(_stream.time * 10) / 10; 168 var bufferTime:Number = _stream.bufferTime < (item.duration - position) ? _stream.bufferTime : (item.duration - position); 169 var bfr:Number = Math.round(_stream.bufferLength / bufferTime * 100); 180 181 var bfr:Number; 182 if (!livestream) { 183 var bufferTime:Number = _stream.bufferTime < (item.duration - position) ? _stream.bufferTime : (item.duration - position); 184 bfr = Math.round(_stream.bufferLength / bufferTime * 100); 185 } else { 186 bfr = Math.round(_stream.bufferLength / _stream.bufferTime * 100); 187 } 188 170 189 if (bfr < 95 && position < Math.abs(item.duration - _stream.bufferTime - 1)) { 171 190 if (state == PlayerState.PLAYING && bfr < 20) { 172 191 _stream.pause(); 192 _bufferFull = false; 173 193 setState(PlayerState.BUFFERING); 174 194 _stream.bufferTime = config.bufferlength; … … 176 196 } 177 197 } else if (bfr > 95 && state == PlayerState.BUFFERING) { 178 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_BUFFER_FULL);179 198 _stream.bufferTime = config.bufferlength * 4; 180 199 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_META, {metadata: {bufferlength: config.bufferlength * 4}}); 181 } 182 183 if (state == PlayerState.BUFFERING) { 200 if (!_bufferFull){ 201 _bufferFull = true; 202 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_BUFFER_FULL); 203 } 204 } 205 206 if (state == PlayerState.BUFFERING || state == PlayerState.PAUSED) { 184 207 //TODO: This works, but it looks weird, as the bufferTime is changing 185 //sendBufferEvent(_stream.bufferLength / _stream.bufferTime * item.duration); 208 /* 209 if (!_bufferFull){ 210 sendBufferEvent(_stream.bufferLength / _stream.bufferTime * item.duration); 211 } 212 */ 186 213 } else if (position < item.duration) { 187 214 if (state == PlayerState.PLAYING && position >= 0) { … … 200 227 _position = pos; 201 228 clearInterval(_positionInterval); 229 _positionInterval = undefined; 202 230 _stream.seek(position); 203 _positionInterval = setInterval(positionInterval, 100);204 //_stream.resume();205 //super.play();231 if (!_positionInterval) { 232 _positionInterval = setInterval(positionInterval, 100); 233 } 206 234 } 207 235 … … 217 245 _stream.client = new NetClient(this); 218 246 _video.attachNetStream(_stream); 219 _positionInterval = setInterval(positionInterval, 100); 247 if (!_positionInterval) { 248 _positionInterval = setInterval(positionInterval, 100); 249 } 220 250 _stream.play(getID(item.file)); 221 251 } … … 242 272 case 'NetStream.Seek.Notify': 243 273 clearInterval(_positionInterval); 244 _positionInterval = setInterval(positionInterval, 100); 274 _positionInterval = undefined; 275 if (!_positionInterval) { 276 _positionInterval = setInterval(positionInterval, 100); 277 } 245 278 break; 246 279 case 'NetConnection.Connect.Rejected': … … 274 307 _unpublished = true; 275 308 break; 309 case 'NetStream.Buffer.Full': 310 if (!_bufferFull) { 311 _bufferFull = true; 312 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_BUFFER_FULL); 313 } 314 break; 276 315 } 277 316 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_META, {metadata: evt.info}); … … 287 326 _started = false; 288 327 clearInterval(_positionInterval); 328 _positionInterval = undefined; 289 329 super.stop(); 290 330 if (_smil) {
Note: See TracChangeset
for help on using the changeset viewer.
