I’ve a problem when I trying to resume background music after pressing power button , I found that the Background Music are not playing but the sound effect have no problem.
This issue only appear in Android 4.0 , 4.0.3 and 4.1
I’m having the same problem.
I think that the reason is the activity isn’t resuming, so the code for playing the music isn’t running.
Try to see what activity functions are being called in this situation.
I remember hearing the key here is to listen to focus changes, but I didn’t find the time looking into it.
I know this thread is a bit old but I was looking for a solution for another issue, got to this question and I know the answer
On the Cocos2dxActivity.java, you need to change a couple methods and add another (overriden) one:
@Override
protected void onResume() {
super.onResume();
Cocos2dxHelper.onResume();
// Comment this off this.mGLSurfaceView.onResume();
}
@Override
protected void onPause() {
super.onPause();
Cocos2dxHelper.onPause();
// Comment this off this.mGLSurfaceView.onPause();
}
// Add this one
@Override
public void onWindowFocusChanged(boolean focus){
if(focus){
this.mGLSurfaceView.onResume();
}
else
{
this.mGLSurfaceView.onPause();
}
}
You must remember, also, to add SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); to AppDelegate::applicationWillEnterForeground() on AppDelegate.cpp.
I tried the solution above but it still doesnt work on cocos2d-x 2.2.3 and kitkat 4.4 … does this work for 4.1, 4.2 , etc??? … Do i need to do something else to make it work??. is it because I get mediaplayer finalized without being released once onPause is called in java!!! I cant even resume music as it is released I think