away168 Posted January 29, 2014 Share Posted January 29, 2014 Hi guys, I'm having trouble in playing HTML5 audio in mobile devices. It appears like it doesn't want to run on autoplay, or triggered by the game code. It only works when it is directly triggered by user input (I read that from Apple that it is some security reason). My solution was to put a "ad"-like screen before getting into the game (I could replace it as my game studio name), and enable tap screen to play all the music to trigger them so they are available throughout the game. But I feel that this is too hackish and sometimes producing bug by the time I tap the screen to trigger them (which plays them all!). Any other solution? thanks! Quote Link to comment Share on other sites More sharing options...
1-800-STAR-WARS Posted January 30, 2014 Share Posted January 30, 2014 From my experience it's not possible to hack around that limitation, no. The 'ad' screen is good, but seeing as part of the reason is that people don't want their mobiles randomly blurting out sound on the bus etc, you could present them with a 'do you want to enable sound?' screen before the game, and have your sound-enabling code trigger if they click 'yes'. Could be seen as a great convenience for some and I've seen it implemented in some Flash games. For the stuff I work on, we use a single sound sprite and no background music - so for us it's as simple as:var initSound = function () { sprite.play(); setTimeout(function () { // the timeout isn't completely necessary but solves some issues on older devices/buggy browsers sprite.stop(); }, 0); document.removeEventListener('touchstart', initSound, false);}document.addEventListener('touchstart', initSound, false); Quote Link to comment Share on other sites More sharing options...
away168 Posted February 5, 2014 Author Share Posted February 5, 2014 Good idea lewis, thanks! Quote Link to comment Share on other sites More sharing options...
venam Posted February 11, 2014 Share Posted February 11, 2014 From a lot of research I've found out that audio support on mobile is a real pain.On ios you cannot play 2 sounds at the same time and autoplay doesn't work, it needs to be initiated by an event triggered by the user.Thus, I've found a nifty solution online: creating audio sprites.https://gist.github.com/753003This might turned out to be helpful. Quote Link to comment Share on other sites More sharing options...
enpu Posted February 12, 2014 Share Posted February 12, 2014 On iOS 6-7 and Android Chrome you can use Web Audio API.http://caniuse.com/audio-apihttp://www.html5rocks.com/en/tutorials/webaudio/intro/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.