Jump to content

Audio overhaul for Phaser 1.0


rich
 Share

Recommended Posts

I've spent a long time working on this but I'm happy to say that Phaser 1.0 features a complete audio overhaul. It was literally rebuilt from the ground-up. I like bullet-point feature lists, so here is one :)

 

  • Full Web Audio and legacy Audio Tag support
  • Global and Sound specific mute and volume controls
  • Intelligently handles the iOS playback locking issue, where you can't load/play audio until a touch event has been received
  • Loop both web audio and audio tag
  • Playback from any position
  • Multi-format loader. Just give the loader an array of sound files and it'll load the first one your device supports
  • Loader linked to iOS playback lock, so if the device is in a locked state it will defer loading until unlocked
  • Handles file decoding without bunching up. mp3s for example can often take a while to decode, playback happens on completion
  • Easily create audio sprites by defining markers within a single sample and giving them unique names
  • Audio sprites work across web audio and legacy audio, so you can batch your sounds together into one mp3 even when using web audio
  • Sound events: load, play, loop, stop, restart
  • Easy access to a sounds gainNode and context so you can implement your own effects
  • Easily disable Web Audio / legacy Audio support, regardless of what the browser can handle
  • Easily disable the whole sound system so you can link in your own 3rd party audio library if you wish :)

Getting very excited about starting to prepare the 1.0 release :)

Link to comment
Share on other sites

For the iOS lock if they are on iOS5, and thus legacy Audio only, then I defer the load of the Audio tag data until the games first touch event, yes. If they are on iOS6 then I wait for the first touch event and then dynamically create a tiny little bit of audio that is silence and play it - because if you don't as you know the audio system remains locked! I do this because it's not guaranteed that any sounds will have loaded or are queued to be played when the first touch event is received.

Link to comment
Share on other sites

This sounds great! Is it being built in such a way that it could be used independently from the rest of Phaser? Say if I had a game I wanted / needed to build with a different framework for whatever reason, could I grab the Phaser Audio module and use it for the sound in that game?

Link to comment
Share on other sites

Use you only the Audio API for that?

Exmaple: <audio> HTML Tag or over Javascript "var sound = new Audio();",..

 

Better solution is to use the AudioContext, but you dont have Problems on Mobile devices.

For example, Apple forbids "easy for use autoplay sounds" by using the Audio-Tag or the new Audio() API.

 

Best solution: http://www.html5rocks.com/en/tutorials/webaudio/intro/

Link to comment
Share on other sites

Phaser uses both the audio tag AND the Web Audio API.

 

Web Audio isn't very well supported on mobile yet, so any decent game framework has to support both methods imho.

 

Apple forbids auto playing ANY sound, no matter if it's audio tag or web audio.

Link to comment
Share on other sites

Web Audio isn't very well supported on mobile yet, so any decent game framework has to support both methods imho.

 

Apple forbids auto playing ANY sound, no matter if it's audio tag or web audio.

Sure, but i says that you use the AudioContext-API not the Audio-API.

 

I have seen that on an other html5 game - And HERE sounds will be automatical played on iOS!

I search the game on my browser-chronic and give you an link tomorrow.

Link to comment
Share on other sites

AudioContext is the Web Audio API! When I talk about Web Audio it's exactly the same thing. Phaser supports using the Audio tag and AudioContext (Web Audio).

 

You cannot play sounds automatically in iOS, even using AudioContext. The only reason that demo link you provided above works is that you have to press the "Play" button to get it started. If you don't start playback directly from a user initiated touch event then all AudioContext playback enters a SCHEDULED state in the context buffer.

 

I suspect you misread my post where I said "Apple forbids auto playing ...", i.e. playing sounds without any user intervention. I didn't mean they don't allow audio! iOS6 is the best for audio playback right now, but you still have to kick it off from a touch event.

Link to comment
Share on other sites

Okay, than i have understand you, Sorry.

Yet i have read it on the API Documentation. In iOS 6 the user muss interact the first time to play the Audio.

But here we can create a Splashscreen and the user must click/tap on a button or what else.

Otherwise an a Gamemenu exists Sound settings - These are on iOS disabled first time. If the user set that "on", the interaction start the sounds on the background.

Link to comment
Share on other sites

Yes the most common way to get around it is to have a "Music On" button on the game menu. Because as soon as the user touches it you have the permissions you need to start the audio downloading (for Audio) or playing (for AudioContext).

 

An alternative is to just have silence on the menu and not start any audio at all until they press Play to enter the game.

Link to comment
Share on other sites

  • 5 months later...
 Share

  • Recently Browsing   0 members

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