我正在构建一个非常简单的播放器并且在我的MediaPlayer上设置了缓冲区大小(mediaPlayer.bufferTime = BUFFER_TIME)。这是有效的,但我想在它开始缓冲时显示图形。我在我的媒体播放器上有一个事件监听器来显示和隐藏,但它似乎没有正常工作。这样做的最佳方法是什么?
以下是我在某处找到的样本中的内容---
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;
}
答案 0 :(得分:3)
尝试在BUFFERING_CHANGE
上设置MediaPlayer
事件监听器:
_mediaPlayer.addEventListener(BufferEvent.BUFFERING_CHANGE,
bufferingChangeHandler);
...
private function bufferingChangeHandler(e: BufferEvent): void
{
trace("buffering " + (_mediaPlayer.buffering ? "in progress" : "finished"));
_ui.isWaiting = _mediaPlayer.buffering;
}