AS3 Record Audio (FMS2),Timer,Sound

使用AS3+Flash Media Server2.0(3.0應該也沒問題)處理錄影、錄音

Click”閱讀更多”Read Full text

 

var nc:NetConnection = new NetConnection();
nc.objectEncoding =ObjectEncoding.AMF0 ;

nc.connect("rtmp://localhost/FMSRecordAudio");
nc.addEventListener (NetStatusEvent.NET_STATUS ,statusHandler);


var ns:NetStream;




var minuteTimer:Timer = new Timer(1000, 30);
minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);

function onTick(event:TimerEvent):void {
trace(event.target.currentCount);
}
function onTimerComplete(event:TimerEvent):void {
ns.publish("false");
trace("done");
}


function statusHandler(e:NetStatusEvent ):void{
if (e.info.code == "NetConnection.Connect.Success") {
trace("Connect success");
ns = new NetStream(nc);
ns.bufferTime=2;
var mic:Microphone = Microphone.getMicrophone(1);
mic.rate=22;
ns.attachAudio(mic);
ns.addEventListener(NetStatusEvent.NET_STATUS, playStatusHandler);
}
}
function playStatusHandler(event:NetStatusEvent):void{
trace(event.info.code);
}




// record the audio to the stream
var currentFileName=String;


var snd:Sound = new Sound();
snd.load(new URLRequest("xmas.mp3"));



function recordAudio(event:MouseEvent):void{
var fileName:String = String(timestamp.getTime() + (count++));
currentFileName=fileName;
ns.publish(fileName, "record");
minuteTimer.start();
flash.media.SoundMixer.stopAll();
snd.play();
}


// plays back the audio that was recorded
function playRecordedAudio(event:MouseEvent):void{
flash.media.SoundMixer.stopAll();
trace(currentFileName);
ns.play(currentFileName);
ns.addEventListener(NetStatusEvent.NET_STATUS, playStatusHandler);
}

0 意見:

張貼留言