开发者

force close when music stops - Android

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜