LuckieLordie

Reliable audio playback on devices

Recommended Posts

Hi again!

 

I'm having trouble getting the audio to play reliably on devices and I wanted some tips of people who have managed it!

 

At the minute I have a sound in my game loaded with :

this.game.load.audio('EngineAudio', ['bin/audio/RocketNoise.mp3']);

then in the update of my preloader:

if(this.cache.isSoundDecoded('EngineAudio')){	this.game.state.start('Splash');			}

added using this:

this.engineNoise = this.game.add.audio('EngineAudio');

and played like this:

if(this.isEngineFiring){	this.smokeEmitter.on = true;	if(!this.engineNoise.isPlaying){ this.engineNoise.play(); }	}else{	this.engineNoise.stop();	this.smokeEmitter.on = false;}

am I missing anything important? 

 

Most of the time the audio just doesn't play when I try to use it on device. It does however work as intended on desktops.

 

Thanks!

Share this post


Link to post
Share on other sites

You'll likely get better help if you specify which device type, which OS version, etc. you are trying with.

 

Well I tried it on the Asus MeMo pad -ME173X with Android 4.2.1. In the default browser the sound loaded fine and the volume was good. However on the same device using chrome it played the sound but for some reason was much quieter. On the Nexus 7 using chrome there was no sound played through the device at all. Currently waiting for an IPad 2 to charge so I can test on safari through that.

 

Edit: no sound played in safari. 

Share this post


Link to post
Share on other sites

Should this effect fire often / frequently? If so I would rethink how you're doing it a little. If the sound is small enough then go for an encoding format that decodes almost instantly (such as a wav file) so you don't incur any start-up costs waiting for the sound. Alternatively I've used an approach in a game where the sound was continuously playing and all I effectively did was to change the volume on it (i.e. muted it and unmuted as needed). Worked well in my case at least.

 

Are any other sounds in the game working? I still reckon if you've got total silence from web audio capable mobile browsers the sound system is still locked.

Share this post


Link to post
Share on other sites

Should this effect fire often / frequently? If so I would rethink how you're doing it a little. If the sound is small enough then go for an encoding format that decodes almost instantly (such as a wav file) so you don't incur any start-up costs waiting for the sound. Alternatively I've used an approach in a game where the sound was continuously playing and all I effectively did was to change the volume on it (i.e. muted it and unmuted as needed). Worked well in my case at least.

 

Are any other sounds in the game working? I still reckon if you've got total silence from web audio capable mobile browsers the sound system is still locked.

It's the sound for some thrusters, it's triggered when the user presses the screen so I'd say it's pretty often. I managed to whittle down some more on the devices that weren't working. With the IOS devices that didn't produce sound reliably they were on IOS 5.0.1, any devices on 6 onwards worked perfectly. With regards to the Android devices the Nexus 7 was the only one that didn't work, after upgrading Chrome to the latest version it worked fine afterwards. I hope that's helpful to you! 

 

Edit: Thanks for the tips regarding sound formatting!

Share this post


Link to post
Share on other sites

Right that makes a lot more sense. Basically everything that works fine is using Web Audio - everything that is performing badly is using legacy audio, which is par for the course.

 

If you want to support legacy audio only devices you've got a couple of options:

 

1) Don't have any sound at all just for legacy audio browsers (lots of html5 games use this approach)

 

2) Use an Audio Sprite, so there is only 1 sound file split into sections, a different sample per section - the thrusters could be part of that. It will still perform badly though, the latency when jumping around an audio sprite on old devices can be horrible.

 

3) Don't have any sound effects, instead just play a piece of ambient music or something. Again only on legacy audio devices (use the full sound experience on web audio). You can check via:

if (game.device.webAudio) { do really cool fx } else { don't }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.