flash on 2011-2-9 typester forked:4favorite:0lines:74license : MIT License modified : 2011-02-09 23:10:36 Embed Tweet 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; nc.connect("rtmp://" + address.text + ":8080"); } 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; } } } } Code Fullscreen Preview Fullscreen status NetConnection codec encodeQuality SoundCodec.SPEEX objectEncoding ObjectEncoding.AMF0 label client setSilenceLevel close Microphone.getMicrophone connect NetStatusEvent.NET_STATUS text NetStream code height StageAlign.TOP_LEFT width sort new page view favorite forked pv69 forked from: flash on 2011-2-9.. tmash06 forked:0 favorite:0lines:74 (diff:2) pv102 forked from: flash on 2011-2-9.. tmash06 forked:0 favorite:0lines:75 (diff:22) pv78 forked from: flash on 2011-2-9.. tmash06 forked:0 favorite:0lines:75 (diff:2) pv185 forked from: flash on 2011-2-9.. KAMEDAkyosuke forked:1 favorite:1lines:74 (diff:4)