當我重複播放一個檔案的時候,爆出各種錯, isPlaying stop,都會不同的報錯,下面是我的程式碼,請大家幫忙下! 謝謝!
public void playerVoice(String json) {
if (TextUtils.isEmpty(json))
return;
JSONObject jsonObject = JSON.parseObject(json);
if (player == null) {
player = new MediaPlayer();
player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
player.start();
}
});
player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
mp.reset();
}
});
}
try {
if (player.isPlaying()) {
player.stop();
player.reset();
}
} catch (Exception e) {
player.stop();
player.reset();
}
try {
player.setDataSource(jsonObject.getString("fullPath"));
player.prepareAsync();
} catch (IOException e) {
e.printStackTrace();
}
}
player.reset();把這句程式碼去掉之後試試看