簡體   English   中英

我在播放音頻時媒體播放器有問題,即使我退出應用程序它也不會停止我如何發布此代碼?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM