flex – AS3中准确的BPM事件监听器

前端之家收集整理的这篇文章主要介绍了flex – AS3中准确的BPM事件监听器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试将动画同步到特定BPM的音乐.我尝试过使用Timer但是在处理小间隔时(毫秒)并不准确.我做了一些阅读,发现了另一种使用小型静音音频文件和SOUND_COMPLETE事件作为计时器的方法.

我用这段代码用了167ms长的声音文件.

  1. package
  2. {
  3. import flash.events.Event;
  4. import flash.events.EventDispatcher;
  5. import flash.media.Sound;
  6. import flash.media.SoundChannel;
  7. import flash.net.URLRequest;
  8.  
  9. public class BetterTimer extends EventDispatcher
  10. {
  11. private var silentSound:Sound;
  12.  
  13. public function BetterTimer(silentSoundUrl:String):void {
  14. super();
  15. silentSound = new Sound( new URLRequest(silentSoundUrl) );
  16. silentSound.addEventListener(Event.COMPLETE,start);
  17. }
  18. public function start():void {
  19. this.timerFired( new Event("start") );
  20. }
  21. private function timerFired(e:Event):void {
  22. dispatchEvent( new Event("fire") );
  23. var channel:SoundChannel = silentSound.play();
  24. channel.addEventListener(Event.SOUND_COMPLETE,timerFired,false,true);
  25. }
  26. }
  27. }

这仍然没有留下来. Flash Player是否具有声音准确性?

解决方法

这是非常棘手的正确!有一个名为 BeatTimer的小型lib试图这样做.我自己没有尝试过这个代码,但是如果它做了它声称它应该正是你需要的东西.

猜你在找的Flex相关文章