在AS3准确BPM事件监听器 [英] Accurate BPM event listener in AS3

查看:146
本文介绍了在AS3准确BPM事件监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图同步动画音乐在特定的BPM。我已经使用定时器尝试,但它在与以毫秒为单位的小间隔处理是不准确的。我做了一些阅读和发现,使用细无声的音频文件和SOUND_COMPLETE事件作为定时器的替代方法。

I'm trying to sync animation to music at a specific BPM. I've tried using the Timer but it isn't accurate when dealing with small intervals in milliseconds. I did some reading and found an alternate method that uses a small silent audio file and the SOUND_COMPLETE event as a Timer.

我用167ms长的声音文件与此code。

I used 167ms long sound file with this code.

package
{
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;

    public class BetterTimer extends EventDispatcher
    {
        private var silentSound:Sound;

        public function BetterTimer(silentSoundUrl:String):void {
            super();
            silentSound = new Sound( new URLRequest(silentSoundUrl) );
            silentSound.addEventListener(Event.COMPLETE, start);
        }
        public function start():void {
            this.timerFired( new Event("start") );
        }
        private function timerFired(e:Event):void {
            dispatchEvent( new Event("fire") );
            var channel:SoundChannel = silentSound.play();
            channel.addEventListener(Event.SOUND_COMPLETE, timerFired, false, 0, true);
        }
    }
}

这仍然不能停留在跳动。是Flash播放器能够精确度的声音?

This still doesn't stay on beat. Is the Flash Player capable of accuracy with sound?

推荐答案

这是非常棘手得到正确的!有一个小的lib称为 BeatTimer ,试图做到这一点。我没有试过$ C C $自己,但如果它做什么,它声称它应该是正是你需要的。

This is very tricky to get right! There's a small lib called BeatTimer that tries to do this. I haven't tried this code myself, but if it does what it claims it should be exactly what you need.

这篇关于在AS3准确BPM事件监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆