audioEngine not playing in Firefox, using minified/compiled lib (3.0 & 3.1)

I’m having an issue where audio is not playing in Firefox (32.0.3, running in OSX 10.8.5). This only occurs if I use minified JS.

I’m using: cocos2d-html5, version 3.0 (I’ve also tested this in version 3.1)

I think this can be easily reproduced for the “moon warriors” example project. Here’s what I’m doing:

  1. Download the “3.0-final” cocos release zip from https://github.com/cocos2d/cocos2d-html5/releases

  2. Go to the /frameworks/cocos2d-html5/tools directory and run “ant” via the command line.

  3. Open /samples/js-moonwarriors/index.html and replace the CCBoot.js path ("…/…/frameworks/cocos2d-html5/CCBoot.js") with the minified source path ("…/…/frameworks/cocos2d-html5/lib/cocos2d-js-v3.0-min.js").

  4. Run the moonwarriors sample as you normally would.

When I test on Firefox, I don’t hear any music using the minified lib.

I’ve also tested the 3.1 release, but the problem seems to be the same there, too (and the performance of my actual game is worse when I use the minified 3.1 library, so I’m hesitant to upgrade).

Does anyone have any thoughts on how to fix or otherwise address this audio issue?

2 Likes

I’m updating just in case someone else with the same problem finds this post.

As far as I can tell, it seems FF may be more susceptible to bad closures / namespace issues in minified code than other browsers, but I wasn’t able to track anything down that confirms it’s the issue here. I ended up just reverting to the unminified library in order to release the game.

It looks like there’s already an open issue in github (from June 2014) for this:
https://github.com/cocos2d/cocos2d-js/issues/524

We will retest it in this week, please keep tuned

Also have the same problem

Long and winding road…

I have the same problem.
Someone fix this problem?

3.2 JS here… I use FF and Chrome
I have no problems with playing sound Effects. (.ogg)

cc.audioEngine.playEffect(sfx_Punch01);

oops… now i get bugs, too ))

I have the same when join all files in singe .js file.
I tried many variants, but still nothing…
If someone doesn’t have this problem, please let us know.

We found a way how to fix it. Sounds in firefox doesn’t work when framework cocos2d-html5 minified, because there is problem with AudioBufferSourceNode. If SWA will be false (CCAudio.js) then sound works ok in all browsers.

@Wadimir, your idea doesn’t seem to work on me, or maybe I didn’t get it.
To test your idea quickly, I changed line 455 in CCAudio.js to: var SWA = false,//polyfill.webAudio, but it seems to give me the same result: No sound in Firefox with minimized JS.

I use Cocos2d-JS v3.3.

EDIT: Thanks to a friend, I noticed something even more interesting. Your fix does work, but loading it via DOM is actually randomly timing out the audio loads, no matter the format or size. It sometimes loads one of the sounds. The others are reported in console as audio load timeouts.

Any idea why?

I have the same problem.

Sorry~ everybody.This is my fault.

Try this, should fix the problem.
https://github.com/cocos2d/cocos2d-html5/pull/2709

Thanks @VisualSJ ,

This modification does not fix the problem, there is no sound in Firefox :frowning:

code :

cc.audioEngine.playEffect("res/mysnd.mp3");

Do not solve the problem for me either.

The funny thing is that i’m using a big js with all files concatenated and the audio only works in Chrome. if i use the command line cocos run -p web the audio works fine

I have the same problem :frowning:
This does not fix it for me too…

While developing, everything was fine. But after joining all to one file (cocos compile -p web -m release), it’s not working anymore with Firefox. A fix would be great, as firefox is really popular and currently not usable for cocos2d projects…

I create a pull request to load the right supportTable (from @VisualSJ ).
Does it work for you ?

https://github.com/cocos2d/cocos2d-html5/pull/2719

@thomasjab it works! TY.

That did it! Works great.
Thank you… :smiley:

Well, @thomasjab’s solution does work for me, but I wanted to know why didn’t the DOM loading work as supposed to.

I paste the description from the pull-request I created below.

Improved audio DOM loader (I believe)

While using DOM audio loading and by using this new method, loading is actually working and has stopped failing randomly. It’s always working for me now, at least in Firefox, Chrome and Opera; I have not tested other browsers.

Please, refer to this link as to how I came up with this method: http://stackoverflow.com/questions/8375903/problems-preloading-audio-in-javascript

If you want to test DOM audio loading, simply force SWA to false (line 461 in CCAudio.js).

If this works for everyone, maybe the setTimeout (lines 572 to 581) will not be needed anymore.