[英]I have a problem with Media Player when playing the audio, it does not stop even when I exit the application How do I release this code?
enter code here
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override
public void onCompletion(MediaPlayer mp) {
btPause.setVisibility(View.GONE);
btPlay.setVisibility(View.VISIBLE);
mediaPlayer.seekTo(0);
}
});
}
@SuppressLint("DefaultLocale")
private String convertFormat(int duration) {
return String.format("%02d:%02d"
, TimeUnit.MILLISECONDS.toMinutes(duration)
,TimeUnit.MILLISECONDS.toSeconds(duration) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)));
}
}
enter code here
我認為您每次都在創建一個 Mediaplayer 實例。 確保不是實例化是
MediaPlayer mp;// above the onCreate section
mp=MediaPlayer.create(this, R.raw.animal_kit);
代替
MediaPlayer mp=MediaPlayer.create(this, R.raw.animal_kit);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.