kamaitachi example stream recording
♥1 |
Line 72 |
Modified 2010-10-16 04:04:52 |
MIT License
archived:2017-03-20 09:56:13
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/oXj1
*/
<?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 init():void {
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, status_handler);
nc.objectEncoding = ObjectEncoding.AMF0;
nc.client = this;
nc.connect("rtmp://127.0.0.1/stream/rec");
}
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 start_publish():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;
}
publish_button.enabled = false;
start_button.enabled = true;
stop_button.enabled = true;
// set quality
camera.setMode(320, 240, 30);
camera.setQuality(0, 80);
mic.setSilenceLevel(0);
mic.rate = 22;
video.attachCamera(camera);
ns.attachCamera(camera);
ns.attachAudio(mic);
ns.publish(channel_name, "live");
}
public function record_start():void {
nc.call("record", new Responder(function():void {}), "start");
}
public function record_stop():void {
nc.call("record", new Responder(function():void {}), "stop");
}
]]></mx:Script>
<mx:Panel title="simple live record example" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
<mx:HBox>
<mx:TextInput id="input" width="120"/>
<mx:Button id="publish_button" label="publish" click="start_publish()"/>
<mx:Button id="start_button" label="rec start" click="record_start()" enabled="false"/>
<mx:Button id="stop_button" label="rec stop" click="record_stop()" enabled="false"/>
</mx:HBox>
<mx:VideoDisplay id="video" width="320" height="240" />
<mx:Label id="status" text="Connecting..."/>
</mx:Panel>
</mx:Application>