当我重复播放一个文件的时候,爆出各种错, 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();把这句代码去掉之后试试呢