我想從通過Red5路由的直播流中獲取原始音頻數據。AS3接收netstream.send ByteArray
我可以使用netstream.attachAudio(麥克風)沒有問題,但瞭解不支持原始數據。
我有使用netstream.send通過ByteArray發送音頻數據的代碼。我可以驗證數據正在發送到Red5服務器,並且正在從Red5服務器發送回客戶端(查看網絡流量)。從來沒有嘗試過設置接收數據的客戶端功能。我發現了很多例子,並且實現了一個解決方案,每個例子都應該可以工作。代碼如下:
protected function ncStatus(event:NetStatusEvent):void {
trace("rtmp connection status: " + event.info.code);
if (event.info.code == "NetConnection.Connect.Success") {
upStream = new NetStream(netc);
upStream.client = this;
upStream.attachCamera(_camera);
upStream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
//this.upStream.attachAudio(this._mic);
_mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler, false, 0, false);
upStream.publish("Seat1","live");
}
}
public function micSampleDataHandler(event:SampleDataEvent):void {
upStream.send("audiodata", event.data as ByteArray);
if (txnum==7) {
downStream.play("Seat1");
}
txnum++;
}
public function audiodata(data):void {
var buf2:ByteArray = newBuffer();
var res:Boolean = ane.processEngine(data as ByteArray, buf2, true, true);
if (res)
processBuffer.push(buf2);
if (processBuffer.length > 8)
_sound.play();
}
protected function netStatus(event:NetStatusEvent):void {
trace("netstream status: " + event.info.code + " " + event.target);
if (event.info.code == "NetStream.Publish.Start") {
downStream = new NetStream(netc);
downStream.client = this;
video = new Video();
video.attachNetStream(downStream);
mediaContainer.addChild(video);
downStream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
}
}
視頻來通過沒有問題,數據適量發送到從服務器,沒有錯誤的指示,但功能「audiodata」永遠不會被調用。有任何想法嗎?