Flash AS3 - OGG声音延迟(Adobe Alchemy库)

时间:2012-02-06 18:26:57

标签: actionscript-3

我想用键盘快捷键制作现场鼓。问题是在这种情况下MP3不够好(编码器在声音开始时增加了随机静音)而且闪光灯本身也会造成延迟(我尝试使用已经缓冲的文件播放(specified_start_point_in_miliseconds))。所以我的解决方案是OGG(这种格式是无间隙的)。 我使用Adobe Alchemy librarysimple frontend for it编译的swc文件。一切正常,OGG文件正在播放,但它仍然有很多延迟 - 无论是外部还是嵌入式,以及它的第一次还是第一次。我需要一个解决方案,如何使声音快速播放到按键。 这是我非常简单的示例代码:

import flash.display.Sprite;
import flash.events.*;
import flash.utils.ByteArray;
import flash.events.SampleDataEvent;
import com.mauft.OggLibrary.OggStream;
import com.mauft.OggLibrary.OggEmbed;

public class ogg extends Sprite
{

    [Embed(source="/drumssnare2.ogg",mimeType="application/octet-stream")] private var OGG_FILE:Class   //Embed Ogg file as binary stream

    public function ogg()
    {
    var gameinfo:Sprite=new Sprite();
    gameinfo.graphics.beginFill(0x000000,1);
    gameinfo.graphics.drawRect(0,0,240,16);
    gameinfo.graphics.endFill();
    gameinfo.addEventListener(MouseEvent.CLICK, playOGG);
    addChild(gameinfo);
    //var streamTest:OggStream=new OggStream("http://127.0.0.1/~7z/drumssnare2.ogg");

        var embedTest:OggEmbed=new OggEmbed((new OGG_FILE) as ByteArray)    //Create new instance of OggEmbed

        function playOGG():void
        {
        //var streamTest:OggStream=new OggStream("http://www.vorbis.com/music/Hydrate-Kenny_Beltrey.ogg")

        //streamTest.play(0);
        embedTest.play(0);

        }
    }
}

1 个答案:

答案 0 :(得分:1)

我的Flash CS5.5项目中的音频文件与循环有同样的问题。 我和我的音频总监花了太多时间在as3中找到一个快速且“无间隙”的循环解决方案。 他创建了一个没有任何差距的.aif文件,我在我的库中导入它,从我的Main类调用。 然后,我们改变了声音属性,看起来像这样:

http://s7.postimage.org/6me47lfzv/Screen_shot_2012_02_06_at_4_35_15_PM.png

在actionscript中我像这样调用.aif文件:

var aifSound:AifSound = new AifSound(); 
//AifSound is the name of the file in the ActionScript tab

//creates a new Sound Channel
var scAif:SoundChannel = new SoundChannel();
scAif = aifSound.play(0,999, 1);
好吧,它给了我一个没有间隙,延迟或性能并发症的循环。 试试并发表反馈意见!

ps:抱歉我的英文不好

谢谢stackoverflow !!