embedded mp3 in actionscript3 won't play all the way through

前端 未结 4 1473
余生分开走
余生分开走 2021-01-06 05:47

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

相关标签:
4条回答
  • 2021-01-06 06:30

    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

    0 讨论(0)
  • 2021-01-06 06:38

    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 to mp3.

    Hope that helps someone.

    0 讨论(0)
  • 2021-01-06 06:49

    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.

    0 讨论(0)
  • 2021-01-06 06:54

    Your background Sound instance is probably getting garbage collected., since you're not maintaining a reference to it. Try this:

    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;
    
            private var _backgroundMusic:Sound;
    
            public function BackgroundMusic() 
            {   
                _backgroundMusic = new BG();
                _backgroundMusic.play();
            }
       }
    }
    
    0 讨论(0)
提交回复
热议问题