LuckieLordie Posted November 28, 2013 Share Posted November 28, 2013 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! Link to comment Share on other sites More sharing options...
alex_h Posted November 28, 2013 Share Posted November 28, 2013 You'll likely get better help if you specify which device type, which OS version, etc. you are trying with. Link to comment Share on other sites More sharing options...
LuckieLordie Posted November 28, 2013 Author Share Posted November 28, 2013 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. Link to comment Share on other sites More sharing options...
rich Posted November 28, 2013 Share Posted November 28, 2013 Has the game received a touch event by this point? You won't get any playback in Safari without it as the audio system is locked. Same for Chrome on the Nexus 7. Link to comment Share on other sites More sharing options...
LuckieLordie Posted November 29, 2013 Author Share Posted November 29, 2013 Has the game received a touch event by this point? You won't get any playback in Safari without it as the audio system is locked. Same for Chrome on the Nexus 7. Sorry it took me so long to reply. Yeah I use "activePointer.isDown" to set "isEngineFiring" to true. Link to comment Share on other sites More sharing options...
rich Posted December 2, 2013 Share Posted December 2, 2013 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. Link to comment Share on other sites More sharing options...
LuckieLordie Posted December 2, 2013 Author Share Posted December 2, 2013 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! Link to comment Share on other sites More sharing options...
rich Posted December 2, 2013 Share Posted December 2, 2013 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 } shawnbless and bfmags 2 Link to comment Share on other sites More sharing options...
Recommended Posts