I embedded an mp3 file be used as background music for my app. Though it works fine, the problem is that it doesn't play the whole track, it just plays the first 32 seconds of it (the mp3 file is 1:30 min).
Does anyone here has any idea why?
I've read here that maybe the sound doesn't fit into the supported flash player sound format, but I don't think that's the problem! The file is not that big, but maybe I am wrong?
Any idea whats causing the problem? Or how to fix it? The code is fine, am sure of it (its pretty simple. Just embedded the mp3, initialized the required variable and played the sound. Nothing fancy)
EDIT: the mp3 is encoded at 44100 KHz
EDIT Here is the code, just incase
package
{
import flash.display.Sprite;
import flash.media.Sound;
import flash.media.SoundChannel;
public class BackgroundMusic extends Sprite
{
[Embed(source="swfs/bg.mp3")]
private var BG:Class;
public function BackgroundMusic()
{
var backgroundMusic:Sound = new BG();
backgroundMusic.play();
}
}
}
Your background Sound instance is probably getting garbage collected., since you're not maintaining a reference to it. Try this:
Well, it's been 2 years since original question, but I had the same problem, but only with short (under 2 seconds) files. Turned out the problem was with metadata. If metadata says sound is 1 second long and in reality it's 1.5 seconds, Flash will only play 1 second of sound cutting the rest off.
I solved the problem by not including metadata with the file when converting from
wav
tomp3
.Hope that helps someone.
As the aforementioned link suggests, the problem was indeed with the mp3 file itself. Basically it was too big. So after reducing it from 44kHz stereo 32 bit to 44kHz stereo 16 bit it worked fine, and now it runs all the way through. With that said its kinda weird that we can't embed higher quality mp3 files. I presume that this problem wouldn't be an issue with loading (rather than embedding) but I haven't tested it. If anyone here has an idea on how to fix this problem without reducing the quality of the mp3 please share
I am pretty sure music will restart every time you tell it to play. Is it possible that you are telling it to play several times? If it is always EXACTLY 32 seconds then I don't know but if it is always AROUND the same time maybe pay attention to what you are doing around that time and check if it is possible that you are calling the play() function again.
If your App has some sort of 30 seconds timer somewhere it can definitely be responsible.
EDIT: hehe If the sound is the only thing present in the entire app then never mind. But it's good to keep in mind anyway.