2011-06-29 103 views
1

我正在構建一個非常簡單的播放器,並在MediaPlayer上設置了一個緩衝區大小(mediaPlayer.bufferTime = BUFFER_TIME)。這是工作,但我想顯示一個圖形,每當它開始緩衝。我在我的mediaplayer上有一個Event Listener來顯示和隱藏,但它似乎沒有正常工作。這樣做的最好方法是什麼?使用OSMF設置緩衝區圖形

這是我從一個樣品,我發現某處有---

mediaPlayer.addEventListener (MediaPlayerStateChangeEvent.MEDIA_PLAYER_STATE_CHANGE, _onMediaPlayerStateChange, false, 0, true); 

function _onMediaPlayerStateChange(evt:MediaPlayerStateChangeEvent):void { 
    trace ("_onMediaPlayerStateChange() , evt.state : " + evt.state); 
    switch (evt.state) { 
     case "playing" : 
      posterButton.visible = false; 
      img.visible = false; 
      onPlaying(); 
      break; 
     case "loading" : 
      // 
      break; 
     case "buffering" : 
      onBuffering(); 
      break; 
     case "uninitialized" : 
      // 
      break; 
     case "ready" : 
      // 
      break; 
     default : 
      break; 
    } 
} 

function onBuffering():void { 
    trace("BUFFERING"); 
    bImg.visible = true; 
} 
function onPlaying():void { 
    trace("PLAYING"); 
    bImg.visible = false; 
} 

回答

3

嘗試設置上MediaPlayerBUFFERING_CHANGE事件偵聽器:

_mediaPlayer.addEventListener(BufferEvent.BUFFERING_CHANGE, 
    bufferingChangeHandler); 

...

private function bufferingChangeHandler(e: BufferEvent): void 
{ 
    trace("buffering " + (_mediaPlayer.buffering ? "in progress" : "finished")); 
    _ui.isWaiting = _mediaPlayer.buffering; 
} 
+1

謝謝,這很好! –