我需要帮助才能在开始活动中设置MediaPlayer
的持续时间。
我尝试使用seekTo()
,但效果不正确。
以下是我正在做的事情:
protected void Player(String bURL, int seekTo){
btn = (Button) findViewById(R.id.playpauseBtn);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(bURL);
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (!mediaPlayer.isPlaying()) {
if (seekTo != 0) {
mediaPlayer.seekTo(seekTo);
}
mediaPlayer.start();
}
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
答案 0 :(得分:1)
尝试修改为:
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (!mp.isPlaying()) {
if (seekTo != 0) {
mp.seekTo(seekTo);
}
mp.start();
}
}
});
mediaPlayer.setDataSource(bURL);
mediaPlayer.prepareAsync();