SimpleAudio playEffect() issue?

SimpleAudio playEffect() issue?
0.0 0



Does anybody occur when you use playEffect() to play about 5sec effect mp3 files, and it will stop after 1 or 2 sec playing on Android device ?

It is fine on iPhone, so I think my code is OK.

Just wonder if someone encounter the same issue with me ?

If the answer is yes, do you have any solution about this ?

Thank you.


As I know, Android supports ogg file best. May be you can translate mp3 to ogg and have a try.



Thank you for your reply.

I have tried ogg format, but the result is the same.

I also tried the m4a(aac), it doesn’t help either.

And there is another issue, the sound effect will not play at the first time playing, but works at the second time.

It’s strange, because they all work fine on iOS.

Do you have any suggestion ?

Thank you again.


For your second question, you can refer the comment of Cocos2dxSound.playEffect().
The comment is:

 * Someone reports that, it can not play effect for the
 * first time. If you are lucky to meet it. There are two
 * ways to resolve it.
 * 1. Add some delay here. I don't know how long it is, so
 *    I don't add it here.
 * 2. If you use 2.2(API level 8), you can call 
 *    SoundPool.setOnLoadCompleteListener() to play the effect.
 *    Because the method is supported from 2.2, so I can't use
 *    it here.


I will test the first question.


Thank you…I will try to do these changes…

BTW, I am a lucky guy…ha~


If you preload the effect before playing, you will not meet it.


Dear Minggo:

Thank you for you reply.

I did try the preloads before I post this question.

But I don’t have luck to get it normal. @@~

BTW, I have three different background music to change one by one, and I preload those three mp3 without any problems on iOS, but crash on Android.

After I change to just preload one song, it runs normal.

It’s a limit that I can only preload one background music ?


What is the version of cocos2d-x?
I have not preloaded more than one background music.
On android, you don’t need to preload background music, it is as quick as you play it without preloading.
But I will fix it if it was crashing by preloading more than one background music.


I use the version that fixed the CCUserDefault crash on Android, I think that’s not a formal release version.

Because I direct download that from the google codes.

And that’s weird, because I get playing lag on Android, not on iOS.


The code is ok.
You mean the code can not play effect for first time even it is preloaded before?
I have tested Cocos2denShionTest on g10, and it can play effect at the first time.


Yes, I preloaded those effect files, but still have lags on playing.

I don’t know why, I will do more tests by myself.

Thank you.


Sorry for digging this old thread, but I’ve meet the exactly same problem. Has it be solved? And if so , how? Thanks a lot.


Could you explain what is the exactly problem?
Which version of cocos2d-x did you use?


I used playEffect() to play a long effect mp3 file. It is about half minute long. And when I play it for the first time, I can hear nothing, and the second time, the first one or two second works, but after that the effect is gone.
I used 0.9.1. And this problem only occurs on android.


dear minggo :
i got some issue like this, my sound effect’s length is 1.3minutes, but when its played on android, its like play 10sec then stop automatically.
how can i solve this problem?


Yes, I also found the same problem in android devices, I use cocos2dx - 0.9.1 …
roughly what the problem there…


How about using ogg format?


@minggo, yes, i already use the ogg format. the sound won’t play in 1st time, but when i play it in 2nd time, it play, but its play only 10sec. is this bugs?


@minggo, in asus transformer 101 / TF101, when i run cocos2dxsimplegame on that device, i doing multitouch and that app is crash. the message is “The application cocos2dxsimplegame(,cocos2dx.cocos2dxSimpleGame) has stopped unexpectedly. Please try again” is that bugs?