kamaitachi example live_streaming
♥0 |
Line 83 |
Modified 2010-10-16 03:41:29 |
MIT License
archived:2017-03-09 14:12:53
ActionScript3 source code
/**
* Copyright typester ( http://wonderfl.net/user/typester )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/azUL
*/
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script><![CDATA[
import flash.net.*;
import flash.events.*;
import flash.media.*;
private var nc:NetConnection;
private var ns:NetStream;
private function status_handler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
setStatus("Connected.");
break;
default:
setStatus(event.info.code);
}
}
private function setStatus(text:String):void {
status.text = text;
}
private function connectConn():void {
var host_name:String = host.text;
if (!host_name) return;
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, status_handler);
nc.objectEncoding = ObjectEncoding.AMF0;
nc.client = this;
nc.connect(host_name);
}
private function closeConn():void {
nc.close();
}
private function publishNs():void {
var channel_name:String = input.text;
if (!channel_name) return;
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, status_handler);
var camera:Camera = Camera.getCamera();
if (!camera) {
setStatus("No camera found");
return;
}
var mic:Microphone = Microphone.getMicrophone();
if (!mic) {
setStatus("No mic found");
return;
}
// set quality
camera.setMode(320, 240, 30);
camera.setQuality(0, 80);
mic.setSilenceLevel(0);
mic.rate = 44;
video.attachCamera(camera);
ns.attachCamera(camera);
ns.attachAudio(mic);
ns.publish(channel_name, "live");
}
private function unpublishNs():void {
ns.close();
}
public function onMessage(message:String):void {
message_label.text = message;
}
]]></mx:Script>
<mx:Panel title="simple live publish example" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
<mx:HBox>
<mx:Label text="Host:"/>
<mx:TextInput id="host" width="120" text="rtmp://127.0.0.1/stream/live" />
<mx:Button id="connectConn_button" label="connect" click="connectConn()" enabled="true"/>
<mx:Button id="closeConn_button" label="close" click="closeConn()" enabled="true"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Name:"/>
<mx:TextInput id="input" width="120"/>
<mx:Button id="publish_button" label="publish" click="publishNs()"/>
<mx:Button id="unpublish_button" label="unpublish" click="unpublishNs()"/>
</mx:HBox>
<mx:VideoDisplay id="video" width="320" height="240" />
<mx:VBox>
<mx:Label id="status" text="Connecting..."/>
<mx:Label id="message_label" text=""/>
</mx:VBox>
</mx:Panel>
</mx:Application>