Built-in mp3 in actionscript3 will not play fully

I have attached an mp3 file as background music for my application. Although it works great, the problem is that it does not play the entire track, it just plays the first 32 seconds (mp3 file is 1:30 min).

Can anyone understand why?

I read here that perhaps the sound does not fit into the supported sound format of the player, but I do not think that the problem! The file is not so big, but maybe I'm wrong?

Any idea that is causing the problem? Or how to fix it? The code is fine, I'm sure of it (its pretty simple. Just built-in mp3, initialized the required variable and played the sound. Nothing unusual)

EDIT : mp3 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(); } } } 
+4
source share
4 answers

As mentioned above, the problem was actually with the mp3 file. Basically it was too big. Thus, after decreasing it from 44 kHz stereo 32 bit to 44 kHz stereo 16 bit, it worked fine, and now it goes all the way. With this it was said that we can’t insert better mp3 files. I assume that this problem will not be a problem when loading (not an attachment), but I have not tested it. If anyone has an idea on how to fix this problem without reducing mp3 quality, please share

+2
source

Well, 2 years have passed since the original question, but I had the same problem, but only with short (less than 2 seconds) files. It turned out that the problem is related to metadata. If the metadata says that the sound lasts 1 second, but in fact it is 1.5 seconds, Flash will play only 1 second of sound, disabling the rest.

I solved the problem by not including metadata with the file when converting from wav to mp3 .

Hope this helps someone.

+2
source

I'm sure the music will reload every time you tell her to play. Perhaps you say that you play several times? If it is always ONLY 32 seconds, then I do not know, but if it is always AROUND the same time, perhaps pay attention to what you are doing at this time, and check if it is possible that you call the play () function again.

If your application has some kind of 30 second timer, it can definitely be responsible.

EDIT: hehe If sound is the only thing in the entire application, then it doesn't matter. But in any case, it’s good to keep in mind.

0
source

Your background instance of Sound is probably collecting garbage since you do not maintain a link to it. Try the following:

 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
source

Source: https://habr.com/ru/post/1390283/


All Articles