Can't play sounds when using iframe cross origin

Hello guys.

Sound does not play on Android with Chrome when I load my game from iframe.
Does anyone know what can I do?

I am using AudioSource and cc.audioEngine at cocos 1.3.1.

Thanks

Hi,

I had different audio problems under CC 1.3.x, but when I migrated my games to 1.4.x, they all are gone.

Best regards,
Zsolt

I use cc 1.4 with iframe and sound workd fine. Can i ask you about ads? Are you planning to put ads on your game?

Thanks @PZsolt27 and @nick3d.
I installed the 1.4.1 version but when using iframe it still does not play any sound on Android Chrome.
Actually, it does not work only on cross origin source. Looks like it requires an user interaction to play a sound. Testing with html5 audio tag it does not work with autoplay too.
Still checking what I can do on cocos to solve it…

@nick3d, I am not planning to put ads because the game is for a customer.

Hi @hugomatsu,

what about the audio file permissions?

Best regards,
Zsolt

Hi @PZsolt27.
Can you explain more about this audio file permission?
I am new on html5 game development, I do not know what do you mean.

Hi @hugomatsu

Instead of using AudioSource component have you tried using cc.AudioClip like below example:

ibissounds: {
default: [],
url: [cc.AudioClip]
},

**cc.audioEngine.playEffect(**this.ibissounds[2]);

God Bless…

Sincerely,

Sunday

Hi @hugomatsu,

I have no experience with CORS, but probably you need this:

Best regards,
Zsolt

Hi @luke2125.
Yes I did.
My game uses both way and they doesn’t work.
Thanks

What is the file format?

Best regards,
Zsolt

Thanks @PZsolt27

I did a test here adding .htaccess at the server with

< IfModule mod_headers.c>
Header set Access-Control-Allow-Origin “*”
< / IfModule>

But still not working. I will try to find more about CORS too

mp3 format

Hi all.
I found a solution.

The problem: Sound does not play when using cross origin source on iframe because it requires any interaction to play any sound on Android-Chrome since version 55.
https://www.chromestatus.com/feature/6406908126691328

The solution: AudioContext.status was “suspended” and we should change it to “running” when click on the screen by resuming the context with the code (not sure if there is any better way to call it):
cc.sys.__audioSupport.context.resume();

If someone want to test it, here is my test case, the sound on Android-Chrome only plays after clicking on resume button:
link: http://audio-iframe-test.bitballoon.com/index.iframe.html
this link loads this source in iframe tag: http://audio-test-source.bitballoon.com/index.html

Hope it helps anyone with same problem.
Thanks everybody for the help

1 Like

Your site works fine after clicking in the resume button.

The API has changed since the solution was found - the new code that worked for me is:
cc.Audio._context.resume();

Changed again. This fix is not working any more in 2.0.2

any idea what the new syntax is?