Android Media Player Plays In The Background, But Doesn't Stop When App Killed

后端 未结 10 1734
被撕碎了的回忆
被撕碎了的回忆 2021-01-17 08:15

I\'m new to Android, so I have a problem. In Android I want to play background music as soon as my music player starts and have it continue even if the activity changes from

10条回答
  •  粉色の甜心
    2021-01-17 08:49

    You have to simply call the music.stop() whenever you leave the application. You can do this in onStop() method of your launcher activity if your app consists only one activity.

    I would suggest you to use SoundPool if you want to efficiently play the sounds. Using it you can play lots of concurrent sounds. I also made a demo project of SoundPool. You can find it here

    When you use MediaPlayer object you'll have to manage all the things by own your own. I also used the same in my first game. But now for my new game I'm using SoundPool. It was added in API 1 n still rocks.

提交回复
热议问题