Actionscript3 中嵌入的 mp3 无法完全播放

发布于 2024-12-25 20:53:14 字数 859 浏览 4 评论 0原文

我嵌入了一个 mp3 文件作为我的应用程序的背景音乐。虽然它工作正常,但问题是它不能播放整个曲目,它只播放前 32 秒(mp3 文件为 1:30 分钟)。

这里有人知道为什么吗?

我读过这里,也许声音不适合支持的 Flash 播放器声音格式,但我不认为这是问题所在!文件没有那么大,但也许我错了?

知道是什么导致了这个问题吗?或者如何解决?代码很好,我确信它(它非常简单。只需嵌入 mp3,初始化所需的变量并播放声音。没什么花哨的)

编辑:mp3 以 44100 KHz 编码

编辑这是代码,以防万一

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();
        }

    }
}

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();
        }

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

场罚期间 2025-01-01 20:53:14

正如上述链接所示,问题确实出在 mp3 文件本身。基本上它太大了。因此,在将其从 44kHz 立体声 32 位降低到 44kHz 立体声 16 位后,它工作得很好,现在它一直运行。话虽如此,我们无法嵌入更高质量的 mp3 文件,这有点奇怪。我认为这个问题不会是加载(而不是嵌入)的问题,但我还没有测试过。如果这里有人知道如何在不降低 mp3 质量的情况下解决此问题,请分享

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

天荒地未老 2025-01-01 20:53:14

好吧,距最初的问题已经过去 2 年了,但我也遇到了同样的问题,但仅限于短文件(不到 2 秒)。结果发现问题出在元数据上。如果元数据显示声音长度为 1 秒,而实际长度为 1.5 秒,则 Flash 将仅播放 1 秒的声音,并切断其余部分。

我通过在从 wav 转换为 mp3 时不将元数据包含在文件中解决了该问题。

希望对某人有帮助。

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.

遮了一弯 2025-01-01 20:53:14

我很确定每次你让它播放时音乐都会重新开始。你有可能告诉它玩几次吗?如果它总是恰好 32 秒,那么我不知道,但如果它总是大约在同一时间,也许请注意您在该时间附近所做的事情,并检查是否有可能再次调用 play() 函数。

如果您的应用程序在某个地方有某种 30 秒计时器,那么它肯定是有责任的。

编辑:呵呵如果声音是整个应用程序中唯一存在的东西那么没关系。但无论如何,记住这一点是好的。

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.

雨夜星沙 2025-01-01 20:53:14

您的后台 Sound 实例可能正在被垃圾收集,因为您没有维护对它的引用。试试这个:

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();
        }
   }
}

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();
        }
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文