Playing BG Music Across Activities in Android

后端 未结 6 896
南方客
南方客 2020-11-27 06:27

Hello! First time to ask a question here at stackoverflow. Exciting! Haha.

We\'re developing an Android game and we play some background music for our intro

6条回答
  •  长情又很酷
    2020-11-27 06:55

    Create a static SoundManager using either SoundPools or MediaPlayers.

    Create a static flag called keepMusicGoing.

    Start the music when the first activty is created.

    When switching actvities set keepMusicGoing to true.

    On the onStop event of your activities check if keepMusicGoing is true,if so leave the music on, then set keepMusicGoing to false.

    If they press the home button the keepMusicGoing flag will be false so the music will stop when the activity loses focus.

    Email me and I can send you a couple SoundManagers that I wrote one uses MediaPlayers and the other SoundPools

    Chad

提交回复
热议问题