haden Posted September 20, 2013 Share Posted September 20, 2013 I am updating my game ConnectMe (Phaser 1.00TS083) to play music and sounds. I noticed when playing a music the first time there is a delay of about 10 seconds before hearing the music (on my iPod touch 6.1.3).Is it normal ? Or am I doing something wrong ?? Link to comment Share on other sites More sharing options...
rich Posted September 20, 2013 Share Posted September 20, 2013 I suspect that's the time it took to receive the touch event, then unlocking the device and then to actually download the music*, decode it and start playing it. mp3s take a while to decode, other formats are much faster. * depending on iOS version, 6 would have cached the file. Link to comment Share on other sites More sharing options...
haden Posted September 20, 2013 Author Share Posted September 20, 2013 I am sure it's a silly question, but why aren't audio files loaded with all other assets ? Link to comment Share on other sites More sharing options...
rich Posted September 20, 2013 Share Posted September 20, 2013 They are preloaded if the browser supports web audio. If it doesn't AND the device is touch locked then the simple answer is because they can't be. They can only start to be downloaded when that first touch event happens. Link to comment Share on other sites More sharing options...
haden Posted September 20, 2013 Author Share Posted September 20, 2013 Ok, thanks for the info Link to comment Share on other sites More sharing options...
mwatt Posted September 20, 2013 Share Posted September 20, 2013 Two questions Rich, if you happen to see this (or to anyone who knows of course): 1. If mp3 files have this draw-back (slow decode time) as there a better file format to use that works well in all/most browsers and allows files of near the same size? 2. If sounds cannot load until the first touch event, does it suffice to programmatically invoke a touch event for this purpose? Link to comment Share on other sites More sharing options...
rich Posted September 20, 2013 Share Posted September 20, 2013 1) ogg is much quicker, but much bigger. there are so many ways of encoding mp3s it might just be the ones i've been testing - i would try a different variety of codecs and see what gives the best result. 2) no, it has to be a genuine user initiated touch event. you can't fake it. Phaser already listens for it and does what is needed under the hood, but there is no way to 'trick' the browser. Link to comment Share on other sites More sharing options...
mwatt Posted September 22, 2013 Share Posted September 22, 2013 Thank you for this useful reply. I will change my first and most commonly used sound to be ogg format, and ensure that I load it first. The rest can stay mp3. (This is in conjunction with a mobile game that is primarily text-based and has no animations to speak of, so it doesn't need Phaser, but I am very glad your replies naturally in the context of using Phaser, as I'll be using it for my next game). Ah... but wait. Does this pre-load delay apply to each sound individually? What I mean is, will pre-loads for all sounds start happening once the first one is played via a touch or does each one have to wait for it's own first play attempt? Link to comment Share on other sites More sharing options...
rich Posted September 22, 2013 Share Posted September 22, 2013 If the browser doesn't support Web Audio (which you can detect using game.device.webAudio) then you should be creating an Audio Sprite and using the marker option available in Phaser to play back different parts of it. Because yes, it would have to load every sound, every time. On Web Audio you can preload them all in advance and they play pretty much instantly (depending if they need to decode). On desktop it's a bit different, as some desktop browsers can play multiple Audio Tag tracks at once (IE for example), but on mobile this either doesn't work at all (like on the Kindle Fire) or sucks performance of your game down into the bowls of hell. Link to comment Share on other sites More sharing options...
mwatt Posted September 22, 2013 Share Posted September 22, 2013 Thanks for all your help Rich - I know you've your time is particularly precious right now, so I am all the more appreciative. Link to comment Share on other sites More sharing options...
claire Posted October 8, 2013 Share Posted October 8, 2013 Hi, I am facing audio delay issue also.I had already load the audio in the preloader, so when "create", I add the audio and play, it still takes me more than 5 seconds to play the audio. Is that normal?I thought the preloader is to load the audio before it goes to "create"? Link to comment Share on other sites More sharing options...
rich Posted October 8, 2013 Share Posted October 8, 2013 That delay is almost certainly the mp3 files decoding. Try this and see what happens: preload: function () { this.load.audio('sfx', ['audio/sfx.mp3']); this.load.audio('titleTune', ['audio/title.mp3']); }, create: function () { this.loadingText.content = 'Decoding...'; }, update: function () { if (this.cache.isSoundDecoded('titleTune') && this.cache.isSoundDecoded('sfx')) { // now you can safely change state and music will play instantly on desktop (mobile still requires a touch unlock though) } }, AlexArroyoDuque 1 Link to comment Share on other sites More sharing options...
claire Posted October 9, 2013 Share Posted October 9, 2013 Thanks rich for the useful information. I manage to play the sound once I go in game state, by adding another load song state before start game state. Link to comment Share on other sites More sharing options...
Recommended Posts