seekPo()方法在播放mediaPlayer时效果很好.如果mediaPlayer暂停,当我寻找一个位置并调用start()时,它就会开始播放暂停的位置.
@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); } }
解决方法
由于某些设备的某些原因: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); }