forked from: flash on 2011-2-9
/**
* Copyright KAMEDAkyosuke ( http://wonderfl.net/user/KAMEDAkyosuke )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/18GE
*/
// forked from typester's flash on 2011-2-9
package {
import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.net.*;
import com.bit101.components.*;
public class FlashTest extends Sprite {
private var nc:NetConnection;
private var ns:NetStream;
private var mic:Microphone;
private var address:InputText;
private var mute:CheckBox;
private var status:Label;
private var button:PushButton;
public function FlashTest() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
var vbox:VBox = new VBox(this, 10, 10);
vbox.spacing = 30;
var addr_box:HBox = new HBox(vbox);
new Label(addr_box, 0, 0, "Address:");
address = new InputText(addr_box);
address.height = 20;
address.width = 200;
button = new PushButton(addr_box, 0, 0, "Connect", on_toggle_connect);
button.width = 50;
var opt_box:HBox = new HBox(vbox);
mute = new CheckBox(opt_box, 0, 0, "Mic off");
var status_box:HBox = new HBox(vbox);
status = new Label(status_box, 0, 0, "Not connected.");
}
private function on_toggle_connect(ev:Event):void {
if (nc) {
nc.close();
nc = null;
status.text = "Not connected.";
button.label = "Connect";
return;
}
status.text = "Connecting...";
button.label = "Close";
mic = Microphone.getMicrophone();
if (!mic) {
status.text = "No mic found.";
return;
}
mic.setSilenceLevel(0);
mic.codec = SoundCodec.SPEEX;
mic.enableVAD = true;
mic.encodeQuality = 6;
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, status_handler);
nc.objectEncoding = ObjectEncoding.AMF0;
nc.client = this;
// fot red5 0_9_1
nc.connect("rtmp://" + address.text + "/echo");
}
private function status_handler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
status.text = "Connected.";
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, status_handler);
ns.play("stream");
if (!mute.selected) {
ns.attachAudio(mic);
ns.publish("stream", "live");
}
break;
default:
status.text += "\" + event.info.code;
}
}
}
}