[android] sound cocos2d-x native Android

[android] sound cocos2d-x native Android
0.0 0


Hai, we working as a small team(ios dev, android dev, cocos2d-x dev/me) to build games that interacts actively
with native app such as upload pic, camera, share, leaderboard, etc…

We’re trying to use cocos2d-x library for background music
We can do this in iOS, but force close in Android. We call the library outside Cocos2dxActivity….
Use something like
Cocos2dxHelper.playBackgroundMusic("*.mp3", true);

Is there something wrong with this? Mind that we can call this function inside cocos2dxActivity…
And can Cocos2dxHelper still playing music even if we change the activity?


Can’t you do it inside C++ part?


If you also look into “AppDelegate.cpp” you will see there is a method called “applicationDidEnterBackground()” - if there is a line which stops audio, simply uncomment it, and it will play when you change activities (i.e. run another app), but keep in mind, that it will also keep playing when you try to close your app (by pressing home button for example).


Sadly no. The game is the children of the native. It takes control of the games.
The games only entered if the native said so. Front Menu is made by native.
And we want to play bgm when entering Front Menu.
I actually can do this by copying three methods (initdata, playbgm, createmediaplayer) from cocos2dxmusic to Front Menu activity….
But it’s still dirty though….