Jump to content

Audio delay


haden
 Share

Recommended Posts

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

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

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

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

  • 3 weeks later...

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

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)		}	},
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...