Multiple audio sounds

How can I play two sounds at the same time, for instance a background music and an effect. I have this working for iPhone but on Android when I try to play two sounds the other stops and the application runs really slow. The sample games coming with the framework, for example Crystal Case, seem to have the same problem.

Thanks in advance.

I had tested it on several browsers.

Chrome mobile supports multi sounds playing, but some mobile browsers can’t support it.

What is the browsers you had tested?

Shun Lin wrote:

I had tested it on several browsers.
>
Chrome mobile supports multi sounds playing, but some mobile browsers can’t support it.
>
What is the browsers you had tested?

My biggest issue is with the Android default browser.

Is your android version above 4.0 or under 4.0?

Shun Lin wrote:

Is your android version above 4.0 or under 4.0?

Above, 4.1.2 .

Shun Lin, what have you found on this? I am seeing that there is a problem with audio once files are packed with compiler. They work well with expanded library, but once compiled the audio does not play correctly. It seems like it will not look for other file types and only plays the initial type. Again, this is post-compilation only.

I thought this was perhaps the way I compiled, and have tried many variations. But then today I found that even this occurs with the sample game Moon Warriors. If you play Moon Warriors using the expanded library, the audio works, but if you run it with the included packed file (MoonWarriors-compress.js) the AUDIO WILL NO LONGER PLAY. This is an important issue to resolve.

Thank you,
Sean

Hi, I am writing back to say that when the files for the new version cocos2d-html5 version 2.2 are compiled to a single file, the audio does not work for Moon Warriors in this latest version too.

I just check the single engine file of v2.2, the MoonWarriors works properly.

Could you please check it again with this link MoonWarriors ?
If the audio is broken, please let me know your devices model, OS version and browsers version. Thanks in advance.

Hi Shun,

Thank you for responding. Two things:
* Tested on desktop - no audio on Mac 10.6.8 Firefox 24
* More important - this example you have posted is not a packed release file into one single JS. That is what I am referring to, see attached. My apologies for the wrong term. Maybe this is impossible? But then why is it in the cocos2d.js as an option?

There is an error on Mac Firefox 24 :
[00:13:07.400] HTTP “Content-Type” of “audio/mpeg” is not supported. Load of media resource http://www.cocos2d-x.org/MoonWarriors/res/Music/mainMainMusic.mp3 failed. @ http://www.cocos2d-x.org/MoonWarriors/index.html

You could refer to: http://stackoverflow.com/questions/16760955/http-content-type-of-audio-mpeg-is-not-supported-issue-on-firefox
We will try to fix this issue.

The example I had posted is a packed single file version. Please check line 41 of MoonWarriors-html5.js file.
It is:
SingleEngineFile:‘MoonWarriors-compress.js’, and the “MoonWarriors-compress.js” is the file which includes engine files and game files.

Hi,all.
Yes,it has a problem that audio does not play correctly in advanced compress.
I have fixed this issue:
https://github.com/cocos2d/cocos2d-html5/pull/1177

Xingsen Ma and Shun Lin,

Thank you very much for looking into this. It sounds like there may be a solution. I will try this latest build from github in the next few days and report back if it clears up the issue.

Once again, thanks for being thorough. It is much appreciated.

Best,
Sean

Hi,

I did want to report back that this fix does indeed seem to be working. Thank you very much for getting this resolved.

If anyone wants to test, I created a small app that will play the proper audio file for the device/platform it is played on. You can listen and hear which file type plays on each platform. You can also test if the platform allows sounds uninitiated by the user, as iOS does not.

You will also see that I created the same app as a single file app and it works the same.
* http://welovebutterfly.com/clients/soundtest/
* http://welovebutterfly.com/clients/soundtest-single/

Once again, thank you.
Sean

Hi I have the same issue of two sounds not playing if at same frame. (Chrome on PC) I will investigate more.
Im using 2.2.
Nick