Sound cuts out after approximately 1/4 of the sound has played


(Mitchell_Buckley) #1

I’m making a game using flashpunk in flash builder 4.7. Currently I’m trying to implement some music that I made using garageband on my phone. I took the m4a file and converted it to mp3 using adobe audition, then embedded it in my code as I would anything else, initialized the variable in the begin() function and played and looped it. It plays through about 23 seconds of my 1:09 length track, and only about 5 seconds of my 17 second track, then it either cuts off, or loops if I have loop on.

[Embed(source="assets/Guitar Roots.mp3")]
public static const MUSIC_ROOTS:Class;

Variables.mainMenuMusic = new Sfx(Constants.MUSIC_ROOTS);
Variables.mainMenuMusic.play(0.5);
Variables.mainMenuMusic.loop();

I use the above code for embedding and initialization and playing inside the begin() function, and the update function only contains some code for checking for clicks. if I do nothing, and just let it play, it glitches like this. I restarted my computer (several times, forcibly by blue screen) and it still continues. Not sure why it’s doing this with all my files, but I’ve tried a file off the internet and it does seem to work, so I’m not sure why my files are so weird. they play normally in any other program. any thoughts?


(Zachary Lewis) #2

I did a few Google searches and came up with this StackOverflow question. It seems as if Flash only supports audio encoded at 44100 Hz stereo. You might want to double-check your .m4a encoding.


(Ben Pettengill) #3

Also, kind of off topic, but you really shouldn’t convert one lossy format (m4a) to another (mp3). Each time you re-compress your song, it will use quality. Does Garageband not let you export directly to mp3?


(lordmagnet) #4

An older topic, but I am having this same issue. Since I couldn’t use my .wavs I converted them to .mp3s but they are both (the wav and the mp3) 44100 Hz stereo. I traced the sound length to 1.9853061224489794 seconds when the sound is just over 5 seconds. It seems this is just an issue with my converted sounds, everything else plays just fine. I am using Adobe Media Encoder.

Anyone have some advice?


(Stefan Langeder) #5

The best way to embed audio files into flash is as follows

  1. Add your uncompressed sounds to an Adobe Flash project
  2. Set up the compress rate there
  3. Export as swc (if you use e.g. FlashDevelop)

Flash plays mp3 sounds best if the get compressed with Adobe Flash.


(lordmagnet) #6

I will give that a try. Thanks, Stee.


(Alex Larioza) #7

Does that fix the loop-gap too?


(Stefan Langeder) #8

Yes :wink: I had those problems in the past too.

Same answer on stackoverflow: http://stackoverflow.com/questions/12588769/gapless-sound-loop-in-flash


(Ultima2876) #9

Actually, in my experience it only works some of the time. It depends a lot on the original track… I use a sound engine called SeiOn to get seamless looping, along with the ‘raw wav to swc’ trick (in many years of trying it’s the only way I’ve found to get perfect looping).