Changeset 651


Ignore:
Timestamp:
11/19/09 16:25:51 (3 years ago)
Author:
zach
Message:
  • Fixing YouTubeMediaProvider complete event order
  • Suppressing SoundMediaProvider buffering events
Location:
trunk/fl5
Files:
4 edited

Legend:

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

    r642 r651  
    88        import com.longtailvideo.jwplayer.model.PlaylistItem; 
    99        import com.longtailvideo.jwplayer.player.PlayerState; 
    10  
     10         
    1111        import flash.events.*; 
    1212        import flash.media.*; 
     
    2626                /** ID for the position interval. **/ 
    2727                protected var _positionInterval:Number; 
    28  
     28                /** Whether the buffer has filled **/ 
     29                private var _bufferFull:Boolean; 
    2930 
    3031                /** Constructor; sets up the connection and display. **/ 
     
    7172                /** Load the _sound. **/ 
    7273                override public function load(itm:PlaylistItem):void { 
    73                         _item = itm; 
    7474                        _position = 0; 
    75                         _sound = new Sound(); 
    76                         _sound.addEventListener(IOErrorEvent.IO_ERROR, errorHandler); 
    77                         _sound.addEventListener(Event.ID3, id3Handler); 
    78                         _sound.addEventListener(ProgressEvent.PROGRESS, positionHandler); 
    79                         _sound.load(new URLRequest(_item.file), _context); 
    80                         _positionInterval = setInterval(positionHandler, 100); 
     75                        if (_item != itm) { 
     76                                _item = itm; 
     77                                _sound = new Sound(); 
     78                                _sound.addEventListener(IOErrorEvent.IO_ERROR, errorHandler); 
     79                                _sound.addEventListener(Event.ID3, id3Handler); 
     80                                _sound.addEventListener(ProgressEvent.PROGRESS, positionHandler); 
     81                                _sound.load(new URLRequest(_item.file), _context); 
     82                        } 
     83                        if (!_positionInterval) { 
     84                                _positionInterval = setInterval(positionHandler, 100); 
     85                        } 
     86                        _bufferFull = false; 
    8187                        setState(PlayerState.BUFFERING); 
    8288                        sendBufferEvent(0); 
     
    8894                /** Pause the _sound. **/ 
    8995                override public function pause():void { 
    90                         if (_channel) { 
     96                        if (_positionInterval){ 
    9197                                clearInterval(_positionInterval); 
    9298                                _positionInterval = undefined; 
     99                        } 
     100                        if (_channel) { 
    93101                                _channel.stop(); 
    94102                        } 
     
    106114                                _positionInterval = setInterval(positionHandler, 100); 
    107115                        } 
     116                        if (_channel){ 
     117                                _channel.stop(); 
     118                                _channel = null; 
     119                        } 
    108120                        _channel = _sound.play(_position * 1000, 0, _transformer); 
    109121                        _channel.addEventListener(Event.SOUND_COMPLETE, completeHandler); 
     
    115127                protected function positionHandler(progressEvent:ProgressEvent=null):void { 
    116128                        var bufferPercent:Number; 
     129                         
    117130                        if (_sound.bytesLoaded / _sound.bytesTotal > 0.1 && _item.duration <= 0) { 
    118131                                _item.duration = _sound.length / 1000 / _sound.bytesLoaded * _sound.bytesTotal; 
    119132                        } 
     133                         
    120134                        if (_channel) { 
    121135                                _position = Math.round(_channel.position / 100) / 10; 
     
    124138                                bufferPercent = Math.floor(progressEvent.bytesLoaded / progressEvent.bytesTotal * 100); 
    125139                        } 
     140                         
    126141                        if (_sound.isBuffering == true && _sound.bytesTotal > _sound.bytesLoaded) { 
    127142                                if (state != PlayerState.BUFFERING) { 
     
    129144                                                _channel.stop(); 
    130145                                        } 
    131                                         setState(PlayerState.BUFFERING); 
    132                                 } else { 
     146                                        _bufferFull = false; 
     147                                        if (!progressEvent) { 
     148                                                setState(PlayerState.BUFFERING); 
     149                                        } 
     150                                } 
     151                        } else if (state == PlayerState.BUFFERING && _sound.isBuffering == false && !_bufferFull) { 
     152                                sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_BUFFER_FULL); 
     153                                _bufferFull = true; 
     154                        } 
     155                         
     156                        if (state == PlayerState.BUFFERING) { 
     157                                if (!isNaN(bufferPercent)){ 
    133158                                        sendBufferEvent(bufferPercent); 
    134159                                } 
    135                         } else if (state == PlayerState.BUFFERING && _sound.isBuffering == false) { 
    136                                 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_BUFFER_FULL); 
    137                         } 
    138                         if (_position < _item.duration) { 
    139                                 sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_TIME, {position: _position, 
    140                                                 duration: _item.duration, bufferPercent: bufferPercent}); 
     160                        } else if (_position < _item.duration) { 
     161                                if (state == PlayerState.PLAYING){ 
     162                                        sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_TIME, {position: _position, duration: _item.duration, bufferPercent: bufferPercent}); 
     163                                } 
    141164                        } else if (_item.duration > 0) { 
    142165                                complete(); 
  • trunk/fl5/src/com/longtailvideo/jwplayer/media/YouTubeMediaProvider.as

    r650 r651  
    179179                                        if (state != PlayerState.BUFFERING && state != PlayerState.IDLE) { 
    180180                                                complete(); 
     181                                                _offset = 0; 
    181182                                        } 
    182183                                        break; 
     
    244245                        super.setVolume(pct); 
    245246                } 
    246                  
    247                 /** Complete playback **/ 
    248                 override protected function complete():void { 
    249                         sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_COMPLETE); 
    250                         setState(PlayerState.IDLE); 
    251                         _position = _offset = 0; 
    252                 } 
    253247        } 
    254248} 
  • trunk/fl5/src/com/longtailvideo/jwplayer/player/PlayerVersion.as

    r650 r651  
    33         
    44        public class PlayerVersion { 
    5                 protected static var _version:String = "5.0.649 beta"; 
     5                protected static var _version:String = "5.0.651 beta"; 
    66                 
    77                public static function get version():String { 
Note: See TracChangeset for help on using the changeset viewer.