cocos2d / cocos2d-js

cocos2d-x for JS
http://www.cocos2d-x.org
MIT License
1.86k stars 490 forks source link

how can we play music in our game when it's running on mobile web browser? #1146

Closed owen26 closed 9 years ago

owen26 commented 9 years ago

mobile web browsers seems to have video/audio play restriction where the media file load have to be triggered by a user interaction event such as a "click".

how cocos2d-js suppose to solve this?

I've tested it with the Parkour game tutorial code. It indeed not playing on mobile.

owen26 commented 9 years ago

is there anyone who can reply on this ?

jarsj commented 9 years ago

If it's a restriction by browser, I don't think cocos2d-js can solve it. I guess you will have to live with the fact that music will only play after user clicks atleast once. Shouldn't be a big problem for most games.

pandamicro commented 9 years ago

As @jarsj said, the game engine runs on the JS environment of browser, so the browser have total control, not inversely. There are some restrictions we can not over pass. We indeed try with web audio API, but the behavior still varies on different browsers.

owen26 commented 9 years ago

Thank you guys for the detailed reply. Actually that's exactly what I'm looking for. As the documentation of cocos2d-js does not mention the audio limitation at all, which I think is a crucial part on HTML5 based game development.

Now I can sit tight and investigate my own work-around.