Ignore:
Timestamp:
12/11/09 14:59:21 (3 years ago)
Author:
zach
Message:
  • Updating buffer_full event dispatching for HTTPMediaProvider
  • Adding suppressing duplicate buffer_full events in RTMP
  • Adding livestream capability to RTMP ( http://developer.longtailvideo.com/trac/ticket/648). Note: Livestreams should only call _stream.resume once.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/fl5/src/com/longtailvideo/jwplayer/media/RTMPMediaProvider.as

    r642 r747  
    1414        import com.longtailvideo.jwplayer.utils.NetClient; 
    1515        import com.longtailvideo.jwplayer.utils.TEA; 
    16  
     16         
    1717        import flash.events.*; 
    1818        import flash.media.*; 
     
    4040                /** Save that a file is _unpublished. **/ 
    4141                protected var _unpublished:Boolean; 
    42  
     42                /** Whether the buffer has filled **/ 
     43                private var _bufferFull:Boolean; 
    4344 
    4445                public function RTMPMediaProvider() { 
     
    9293                        _item = itm; 
    9394                        _position = 0; 
     95                        _bufferFull = false; 
    9496                        setState(PlayerState.BUFFERING); 
    9597                        sendBufferEvent(0); 
     
    143145                } 
    144146 
     147                 
     148                /** Determines if the stream is a live stream **/ 
     149                private function get livestream():Boolean { 
     150                        return item.duration == 0; 
     151                } 
    145152 
    146153                /** Pause playback. **/ 
     
    148155                        _stream.pause(); 
    149156                        clearInterval(_positionInterval); 
     157                        _positionInterval = undefined; 
    150158                        super.pause(); 
    151159                        if (_started && item.duration == 0) { 
     
    157165                /** Resume playing. **/ 
    158166                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                        } 
    161173                        super.play(); 
    162174                } 
     
    166178                protected function positionInterval():void { 
    167179                        _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                         
    170189                        if (bfr < 95 && position < Math.abs(item.duration - _stream.bufferTime - 1)) { 
    171190                                if (state == PlayerState.PLAYING && bfr < 20) { 
    172191                                        _stream.pause(); 
     192                                        _bufferFull = false; 
    173193                                        setState(PlayerState.BUFFERING); 
    174194                                        _stream.bufferTime = config.bufferlength; 
     
    176196                                } 
    177197                        } else if (bfr > 95 && state == PlayerState.BUFFERING) { 
    178                                 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_BUFFER_FULL); 
    179198                                _stream.bufferTime = config.bufferlength * 4; 
    180199                                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) { 
    184207                                //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                                */ 
    186213                        } else if (position < item.duration) { 
    187214                                if (state == PlayerState.PLAYING && position >= 0) { 
     
    200227                        _position = pos; 
    201228                        clearInterval(_positionInterval); 
     229                        _positionInterval = undefined; 
    202230                        _stream.seek(position); 
    203                         _positionInterval = setInterval(positionInterval, 100); 
    204                         //_stream.resume(); 
    205                         //super.play(); 
     231                        if (!_positionInterval) { 
     232                                _positionInterval = setInterval(positionInterval, 100); 
     233                        } 
    206234                } 
    207235 
     
    217245                        _stream.client = new NetClient(this); 
    218246                        _video.attachNetStream(_stream); 
    219                         _positionInterval = setInterval(positionInterval, 100); 
     247                        if (!_positionInterval) { 
     248                                _positionInterval = setInterval(positionInterval, 100); 
     249                        } 
    220250                        _stream.play(getID(item.file)); 
    221251                } 
     
    242272                                case 'NetStream.Seek.Notify': 
    243273                                        clearInterval(_positionInterval); 
    244                                         _positionInterval = setInterval(positionInterval, 100); 
     274                                        _positionInterval = undefined; 
     275                                        if (!_positionInterval) { 
     276                                                _positionInterval = setInterval(positionInterval, 100); 
     277                                        } 
    245278                                        break; 
    246279                                case 'NetConnection.Connect.Rejected': 
     
    274307                                        _unpublished = true; 
    275308                                        break; 
     309                                case 'NetStream.Buffer.Full': 
     310                                        if (!_bufferFull) { 
     311                                                _bufferFull = true; 
     312                                                sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_BUFFER_FULL); 
     313                                        } 
     314                                        break; 
    276315                        } 
    277316                        sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_META, {metadata: evt.info}); 
     
    287326                        _started = false; 
    288327                        clearInterval(_positionInterval); 
     328                        _positionInterval = undefined; 
    289329                        super.stop(); 
    290330                        if (_smil) { 
Note: See TracChangeset for help on using the changeset viewer.