Issue with music not stopping on Android devices


#1

Hi,

I am running into an issue where the music will continue to play when I press the home button on an android device.

Within AppDelegate::applicationDidEnterBackground() I have CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();

This works but the loading time of the app coming out of sleep mode is taking a long time. So I tried fixing it by commenting out this.mGLSurfaceView.onPause(); & this.mGLSurfaceView.onResume(); in Cocos2dxActivity.java.

But the result is that the music will continue to play when the home button is pressed.

Does anyone have a work around for this issue?

Thanks in advance!


#2

Can’t say I have any problem or ever seen a problem, I have the standard code, looks like this:

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->stopAnimation();
    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
    SimpleAudioEngine::sharedEngine()->pauseAllEffects();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->startAnimation();
    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
    SimpleAudioEngine::sharedEngine()->resumeAllEffects();
}

#3

Gav GMTDev wrote:

Can’t say I have any problem or ever seen a problem, I have the standard code, looks like this:
>
[…]

Your code will stop the music when the home button is pressed. But this will not work in conjunction with commenting out this.mGLSurfaceView.onPause();

As this line helps the application come out of sleep mode quicker, I require this line to be commented. But the drawback is that the music will play when I press the home button.

I’m looking for a solution to this issue.

Thanks for the reply though.


#4

Why is the app taking a long time to come out of sleep mode? Do you have a lot of graphics in memory or something? I doubt commenting out mGLSurfaceView.onPause() is a good idea.


#5

The images are quite large. That’s why it is taking time to re-load them.