我正在尝试收听我创建的媒体播放器的 OnInfoListener,以便在缓冲开始和结束时获取。
由于某种原因,该事件永远不会触发。
这是我的初始化代码
private void initPlayer(Surface s){
mPlayer = new MediaPlayer();
mPlayer.setSurface(s);
mPlayer.setOnCompletionListener(this);
mPlayer.setOnErrorListener(this);
mPlayer.setOnInfoListener(this);
mPlayer.setOnPreparedListener(this);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(file_url);
mPlayer.prepare();
} catch (IllegalArgumentException e) {
OnError(PLAYER_ERRORS.player_not_loaded, e.getMessage() + "");
} catch (SecurityException e) {
OnError(PLAYER_ERRORS.player_not_loaded, e.getMessage() + "");
} catch (IllegalStateException e) {
OnError(PLAYER_ERRORS.player_not_loaded, e.getMessage() + "");
} catch (IOException e) {
OnError(PLAYER_ERRORS.no_connection, e.getMessage() + "");
}
}
这是我的听众
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
if(what == MediaPlayer.MEDIA_INFO_BUFFERING_START)
{
OnEvent(PLAYER_EVENT.buffering_start);
}
else if(what == MediaPlayer.MEDIA_INFO_BUFFERING_END)
{
OnEvent(PLAYER_EVENT.buffering_end);
OnGotDuration(getDuration());
}
return what == MediaPlayer.MEDIA_INFO_BUFFERING_START || what == MediaPlayer.MEDIA_INFO_BUFFERING_END;
}
有人可以帮我理解为什么会这样吗?谢谢