Jump to content

Audio starts up to 1 minute late (after game is loaded and menu already visible)


valueerror
 Share

Recommended Posts

this is happening on mobile only

i guess that my OGG file needs very long to be decoded.. i also tried with an MP3 and got the same result.. 

 

my music is not that long.. it's a 1.26 minute loop and i have the same problem with a 25sec loop..  (it seems to wait for every audiofile to be decoded before it starts playing.. could this be the problem?

 

 

is there a way to fix that ?  my preloadbar is long gone when the audio finally starts..  if i quickly select a level it even leads to  another problem/bug where both audio files (the menu audio and the level audio) are played..    

 

audio1 should be stopped before audio2 starts but since it is not playing at that specific moment (because it's probably still decoding) it is not stopped.. 

 

is this a bug?

Link to comment
Share on other sites

This is known as the decoding delay. There's nothing you can do to avoid it, all you can do is wait for it to finish (each sound file has a decoding event to let you know when). You control which files auto-decode and which are decoded on play, it's a parameter to the Loader. But they all need to actually decode before they will play, but at least you can control which do it and when.

 

Also understand that not all mp3/ogg files are created equally - there are codecs out there that take longer to decode than others.

Link to comment
Share on other sites

hey rich.. thank you very much for your answer..   

 

so i can't tell my game to decode my "menu background loop" first and immediately play it.

 

i could set some sounds (only needed later) to only decode on play to speed up the process  though..  did i understand you correctly?  

 

(im using audacity with default ogg/vorbis settings to export my audiofiles btw.  any tips for a good codec or export setting ??  

 

thx again :)

Link to comment
Share on other sites

If for example you are loading 6 pieces of audio, but only need 1 of them decoded for the Menu, then you can say "don't autodecode" for the other 5 - then the start-up time would be considerably less as you only need wait for one piece of audio to decode. It will still take time to decode though - and the time that takes depends on lots of factor: CPU load, the device itself, anything else going on in the operating system, the length of the audio, the way it was encoded, etc.

Link to comment
Share on other sites

For "Web Audio", it's a known problem in Chromium on mobile devices and there is a long discussion about the cause -- Firefox on mobile is much faster.

 

You can alternatively HTML5 Audio (regular audio files) instead of Web Audio, Crosswalk, and add "xwalk --disable-gesture-requirement-for-media-playback" inside "platforms\android\assets\xwalk-command-line".

Link to comment
Share on other sites

  • 2 weeks later...

so i tried this approach and the thing is.. this only delayed the problem..  when the game starts only 3 pieces are decoded and played almost immediately..   the big portion gets decoded when the first level starts..  i have 30 seconds delay until the first sounds can be heard..  that's just bad :(

 

so phaser doesn't provide a way to just preload everything at once but start playing the first decoded sound if it's already needed immediately.. it for some reason waits until all sounds are decoded before it plays the sound that is already decoded minutes ago..

 

i found a simple workaround  :ph34r:

 

i set autodecode to false for those sounds that are not needed immediately BUT i make them decode 200ms after my "menu" state is ready - simply by starting it - and stopping it 

Preloader = game.time.events.add(200, function(){if (firststart === true){ music1.play('',0,1,false); music1.stop();  firststart = false;    }} );

this way i can precisely define WHEN a sound is going to be decoded..

any thoughts on this ?

is this bad practice  ?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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