I used MediaPlayer in creating background music in my menu game. it seems to work correctly but when I start another activity then going back on menu. the sounds disappear. how can I play it again whenever the menu activity launch?
heres some of my codes:
logoMusic = MediaPlayer.create(NewMainActivity.this, R.raw.onepiece_sound);
logoMusic.start();
then on my pause method:
protected void onPause() {
super.onPause();
logoMusic.release();
Use the onRestart
method for that.
@Override
protected void onRestart() {
super.onPause();
logoMusic = MediaPlayer.create(NewMainActivity.this, R.raw.onepiece_sound);
logoMusic.start();
}
This will be called only when you go back to the activity, not when you open it for the first time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.