Jump to content

Playing audio in mobile devices


away168
 Share

Recommended Posts

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!  :)

Link to comment
Share on other sites

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);
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...