Sound lag on iPhone

70 views
Skip to first unread message

Vasco

unread,
Mar 31, 2014, 9:54:43 PM3/31/14
to haxef...@googlegroups.com
When I play an ogg sound file on the iPhone, the game freezes for a moment, as if to load the sound. Only after this short delay does the sound play and the game continue. This doesn't seem to happen with wav files.

This is how I play sound files:

#if flash
    FlxG.sound.play("assets/sounds/test.mp3");
#else
    FlxG.sound.play("assets/sounds/test.ogg");
#end


Is this a known problem or am I doing something wrong?

Gama11

unread,
Apr 1, 2014, 4:05:40 AM4/1/14
to
I think you will probably have more luck with this question in the OpenFL forums.

I know that it helps on Android to cache sounds at the start of the app (via FlxG.sound.add()), since you can get lags like that otherwise - I haven't heard about this being an issue on iOS though.

Just a little tip, you might want to write a wrapper function to get the correct extension, so you can do:

FlxG.sound.play(getExtension("assets/sounds/test"));

public function getExtensions(s:String):String
{
   
#if flash
   
return s + ".mp3";
   #else
   
return s + ".ogg";
   
#end
}

Vasco

unread,
Apr 1, 2014, 1:42:18 PM4/1/14
to haxef...@googlegroups.com
Ok, I'll try the OpenFL forums. It seems that the FlxG.sound.add() function only works for Android.

And thanks for the tip! I supposed there was a better way to deal with the extensions...


On Tuesday, April 1, 2014 9:05:15 AM UTC+1, Gama11 wrote:
I think you will probably have more luck with this question in the OpenFL forums.

I know that it helps on Android to cache sounds at the start of the app (via FlxG.sound.add()), since you can get lags like that otherwise - I haven't heard about this being an issue on iOS though.

Just a little tip, you might want to write a wrapper function to get the correct extension, so you can do:

FlxG.sound.play(getExtension("assets/sounds/test"));

public function getExtensions(s:String):String
{
   
#if flash
   
return s + ".mp3";
   #else
   
return s + ".ogg";
   
#end
}



On Tuesday, April 1, 2014 3:54:43 AM UTC+2, Vasco wrote:

Vasco

unread,
Apr 1, 2014, 8:11:07 PM4/1/14
to
Well, on the OpenFL forums they said that I need to load the sounds prior to playing. It would be great if I could just use FlxG.sound.add(), but there's a compiler conditional that only let's it compile for Android. I tried to change that on the Mac, but when I search I can't find any flixel .hx files (only .cpp), don't they exist for the Mac?

EDIT: Ok, I found the hx files (I don't have much experience with Macs), let me see if I can get this to work...

Vasco

unread,
Apr 1, 2014, 8:15:26 PM4/1/14
to
I solved the problem by changing the 3 compiler conditionals in SoundFrontEnd.hx to #if (android || ios)

I would like to do a pull request but I've never done it and it seems confusing :S


On Wednesday, April 2, 2014 12:06:37 AM UTC+1, Vasco wrote:
Well, on the OpenFL forums they said that I need to load the sounds prior to playing. It would be great if I could just use FlxG.sound.add(), but there's a compiler conditional that only let's it compile for Android. I tried to change that on the Mac, but when I search I can't find any flixel .hx files (only .cpp), don't they exist for the Mac?

EDIT: Ok, I found the hx files (I don't have much experience with Macs), let me see if I can get this to work...

On Tuesday, April 1, 2014 6:42:18 PM UTC+1, Vasco wrote:

impaler

unread,
Apr 2, 2014, 2:02:56 AM4/2/14
to haxef...@googlegroups.com

Vasco seems like a sensible pull request if your up for it? Not many of the core developers use macs/iOS and some people implement their own sound pipeline etc.

On 02/04/2014 11:13 am, "Vasco" <vasco....@gmail.com> wrote:
I solved the problem by changing the 3 compiler conditionals in SoundFrontEnd.hx to #if (android || ios)

On Wednesday, April 2, 2014 12:06:37 AM UTC+1, Vasco wrote:
Well, on the OpenFL forums they said that I need to load the sounds prior to playing. It would be great if I could just use FlxG.sound.add(), but there's a compiler conditional that only let's it compile for Android. I tried to change that on the Mac, but when I search I can't find any flixel .hx files (only .cpp), don't they exist for the Mac?

EDIT: Ok, I found the hx files (I don't have much experience with Macs), let me see if I can get this to work...

On Tuesday, April 1, 2014 6:42:18 PM UTC+1, Vasco wrote:

--
HaxeFlixel Development Community
See our github https://github.com/haxeflixel/ and our documentation http://haxeflixel.com/documentation/
---
You received this message because you are subscribed to the Google Groups "HaxeFlixel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haxeflixel+...@googlegroups.com.
Visit this group at http://groups.google.com/group/haxeflixel.
To view this discussion on the web visit https://groups.google.com/d/msgid/haxeflixel/eb6f7947-daa2-4f61-b2b5-6604f321bed9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrei Regiani

unread,
Apr 2, 2014, 4:51:10 AM4/2/14
to
I have a little hack for this and it works perfectly cross-platform: just play every sound (muted) before your game starts.

Create a file Core.hx (or whatever):
package;

import flixel.FlxG;

class Core
{
public static function preloadSounds():Void
{
FlxG.sound.volume = 0;

FlxG.sound.play("my_sound", 0);
// (...) add every sound here
 
FlxG.sound.volume = 1;
}
}

Then on create() of your first FlxScene just call Core.preloadSounds();

Gama11

unread,
Apr 2, 2014, 8:13:00 AM4/2/14
to haxef...@googlegroups.com
The FlxG.sound.add() approach seems preferable to me.
Reply all
Reply to author
Forward
0 new messages