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

后端 未结 10 1730
被撕碎了的回忆
被撕碎了的回忆 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:58

    try this

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)  {
        if (keyCode == KeyEvent.KEYCODE_BACK ) {
            music.stop();
            return true;
        }
    
        return super.onKeyDown(keyCode, event);
    }
    

    else if you have any separate button action for closing the app, there to u can call as music.stop();

提交回复
热议问题