Latency in playing short sounds in Flash 9, Actionscript 3

前端 未结 6 1746
不思量自难忘°
不思量自难忘° 2020-12-15 13:44

I\'ve got a few very short audio clips (less than a second long) to be played on various events (button hover, click, etc). However, there is usually a significant lag betw

相关标签:
6条回答
  • 2020-12-15 13:54

    One solution might be to use an ActionScript library that reads sound files as binary data.

    StandingWave
    https://github.com/maxl0rd/standingwave3
    http://maxl0rd.github.com/standingwave3/

    Also, make sure to check audio settings of the environment around your SWF. I was debugging my app for hours until realizing the latency came from my bluetooth headphone connection.

    0 讨论(0)
  • 2020-12-15 14:02

    I was having bad sound lancency (about 1 full second) with Flash Player 10.0.2.x. The lantency was the same when stopping the sound channel.

    I just upgraded to 10.0.22.x and the problem is gone.

    0 讨论(0)
  • 2020-12-15 14:05

    It's a little thing but:

    function playSound( name:String ):void
    {
       for( var nameSrc:String in soundArray )
       {
          if( name == nameSrc )
          {
             var channel:SoundChannel = soundArray[ name ].play();
             return;
          }
       }
    }
    

    Should be:

    function playSound(name:String):void
    {
        if(soundArray[name])
        {
            soundArray[name].play();
        }
    }
    

    There is no need for a loop look up since that is what the hash table is for. Also, you shouldn't use an Array at all for that since an Array is an ordered set which is indexed using integers. You want to use an Object (or Dictionary) in this case and name it soundMap (since it maps sound names to sound objects).

    As for sound latency -- there should be none. I've done quite a bit of sound in Flash (including tons of one off rollover and rollout sounds) and it has never been an issue. However Flash Player 10 has a new low-level sound API which is described by one of the Adobe engineers in that article. A solution involving that is a bit of a sledge hammer but perhaps you are looking for millisecond accuracy.

    The advice fenomas gives is wise: check the mp3 file for deadspace at the start and end and trim it as close as possible. Also - what is the path from the event handler to your play statement? Are there any possible blocks there? What is the format of the mp3? Flash works best with specific encodings (44.1 hHz and 128 bit I believe).

    0 讨论(0)
  • 2020-12-15 14:08

    I had the exact same problem... until I noticed that the problem was only occurring only while previewing within Flash. Try running the complied swf (it worked for me).

    0 讨论(0)
  • 2020-12-15 14:15

    Well, my first-blush answer is that when I've done things like this, normally I find that sound files have a certain amount of lead time built in. You could check in a sound editor, but What I've done in the past is to import the sound into the Flash IDE, make an empty movie clip, and put the sound on frame 1 of the clip. Then, but editing the frame sound you get a nice little interface to drag the start/end points of the sound playback. Then I used to either attach/remove the clip to play the sound, or leave it somewhere and use frame commands.

    If you're already sure that the lead time is in flash and not the audio then I have no tips or tricks, beyond reasonably obvious things like playing click sounds on key down instead of up...

    0 讨论(0)
  • 2020-12-15 14:17

    I'm having the same problem. Came across this. Apparently if you keep the sound player "going" silently in the background, it doesn't need to "restart" for small sounds. Haven't tried it yet...

    http://www.ghostwire.com/blog/archives/as3-fixing-the-lag-that-arises-when-playing-a-short-sound-effect/

    0 讨论(0)
提交回复
热议问题