I wanted to make live drums play with keyboard shortcuts. The problem was that MP3 is not good enough in this case (encoders adds random silence at beginning of the sound) and also flash itself makes delay (I tried use already buffered file with play(specified_start_point_in_miliseconds)). So my solution is OGG (this format is gapless). I use compiled swc file from Adobe Alchemy library and simple frontend for it. Everything works fine, OGG file is playing, but its still much delay - no matter if its lodeaded external or as embedded, and if its first or n time. I need a solution, how to make sound play fast equally to key press. Here is my very simple example code:
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);
}
}
}