<?xml version="1.0" encoding="utf-8"?>
<tvWindow xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" cornerRadius="7" title="Live Stream" width="460" height="400" creationComplete="doInit()" xmlns:media="flash.media.*">
<mx:Script>
<![CDATA[
import flash.media.*;
import mx.core.UIComponent;
public var tvMaster:Master;
private var ns:NetStream;
private var cam:Camera;
private var mic:Microphone;
private var vidHolder:UIComponent = new UIComponent();
private var vid:Video;
private function doInit():void {
ns = new NetStream(tvMaster.tvNC);
// setup cam
cam = Camera.getCamera();
// setting dimensions and framerate
cam.setMode(320, 240, 20);
// set to minimum of 100% quality
cam.setQuality(0,70);
// setup mic
mic = Microphone.getMicrophone();
mic.rate = 44;
vidHolder.setActualSize(320, 240);
vidHolder.x = 10;
vidHolder.y = 10;
addChild(vidHolder);
vid = new Video(320,240);
vidHolder.addChild(vid);
vid.attachCamera(cam);
}
public function doUnInit():void {
vid.attachCamera(null);
vid.clear();
if (ns != null) {
ns.close();
ns.attachAudio(null);
ns.attachCamera(null);
ns = null;
}
cam = null;
mic = null;
}
private function doBroadCast():void {
var sN:String;
if (ns != null) {
ns.close();
ns.attachAudio(null);
ns.attachCamera(null);
ns = null;
}
ns = new NetStream(tvMaster.tvNC);
ns.attachCamera(cam);
ns.attachAudio(mic);
sN = "stream" + tvMaster.userName + new Date().getTime();
tvMaster.tvNetwork.sendData("LIVE " + tvMaster.currentChannel + ":" + sN + "\n");
ns.publish(sN, "live");
}
private function doStopCast():void {
if (ns != null) {
ns.close();
ns.attachAudio(null);
ns.attachCamera(null);
ns = null;
tvMaster.tvNetwork.sendData("LIVE " + tvMaster.currentChannel + ":" + 0 + "\n");
}
}
]]>
</mx:Script>
<mx:Button x="10" y="328" label="Broadcast" click="doBroadCast()"/>
<mx:Button x="142" y="328" label="Stop Broadcast" click="doStopCast()" />
<mx:HSlider x="10" y="308" id="quality" snapInterval="1" value="75" maximum="100" change="cam.setQuality(0,quality.value)"/>
</tvWindow>