开发者

force close when music stops - Android

开发者 https://www.devze.com 2023-01-06 06:40 出处:网络
another new problem described below: 开发者_如何转开发When I press home button when music STILL plays, it closes correctly, but when the sound (that is five seconds long) has finished and I press hom

another new problem described below:

开发者_如何转开发When I press home button when music STILL plays, it closes correctly, but when the sound (that is five seconds long) has finished and I press home button, it gives me a force close. I have tried an else-statement; with no luck.

protected void onStop() {
    super.onStop();
    if(mp.isPlaying()){
        mp.pause();
    }
}

there my variable mp is a MediaPlayer linked to this mp = MediaPlayer.create(getBaseContext(), R.raw.mainsound);

Ideas?


Is there some code elsewhere that nulls out mp when it finishes playing?


It seems that I solved it. I had a setOnCompletionListener inside my onCreate which lead to I couldn't access my mp, when it stopped.

0

精彩评论

暂无评论...
验证码 换一张
取 消