我可以停止音頻,但如果我檢查我的Android Studio調試窗口,我看到MediaPlayer在後臺工作!如何正確停止MediaPlayer?
我彈奏的聲音那樣:
try {
myMediaPlayer1 = new MediaPlayer();
myMediaPlayer1.setAudioStreamType(AudioManager.STREAM_MUSIC);
myMediaPlayer1.setDataSource("http://myweb.com/audios/1.mp3");
myMediaPlayer1.prepare();
myMediaPlayer1.start();
} catch (Exception e) {
// TODO: handle exception
}
我通過按鈕或OnDestry那樣的點擊停止MediaPlayer的:
@Override
protected void onDestroy() {
super.onDestroy();
myMediaPlayer1.stop();
}
我通過USB連接調試。停止聲音後我看到MediaPlay在後臺運行:
感謝,它的工作原理: 'myMediaPlayer1.setOnCompletionListener(新MediaPlayer.OnCompletionListener(){ @覆蓋 公共無效onCompletion(MediaPlayer的myMediaPlayer1) { releaseMediaPlayer(); } });'' – Json