当seekTo()
正在播放时,mediaPlayer
方法效果很好。如果暂停mediaPlayer
,当我寻找某个职位并致电start()
时,它就会暂停播放。
我的代码如下,在logcat中,我可以看到它正在寻找。
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
if(player == null || player.mediaPlayer == null){
return;
}
Log.e("player status", "status is " + PlayerStatusCache.playerStatus);
if(durationProgress < player.mediaPlayer.getDuration()){
player.mediaPlayer.seekTo(durationProgress);
Log.e("player", "seeking");
} else {
player.mediaPlayer.seekTo(player.mediaPlayer.getDuration() - 1000);
}
}
答案 0 :(得分:0)
由于某些设备的某些原因:SystemClock.sleep(200)
是必要的,因为玩家在搜索到真正完成之前很快就会调用onSeekComplete(MediaPlayer arg0)
。
mMediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
@Override
public void onSeekComplete(MediaPlayer arg0) {
Log.d(TAG, "onSeekComplete() current pos : " + arg0.getCurrentPosition());
SystemClock.sleep(200);
mMediaPlayer.start();
}
});
try {
mMediaPlayer.seekTo(mCurrentPos);
} catch (IllegalStateException e){
Log.d(TAG, e.getLocalizedMessage(), e);
}