Trying to add metadata to a live stream completely fails
Hi. I've been following this document http://help.adobe.com/en_US/flashmediaserver/devguide/WS5b3ccc516d4fbf351e63e3d11a0773d56e-7ff6Dev.html for adding metadata to an FMS live stream from a Flash widget.
I've created a stripped-down version of the code (listed below); the same as the original code except the controls are removed. It works fine only if I comment out the ns.send calls. If I leave in the ns.send calls, no clients are ever able to view anything. I'm using a stock FMS 4.5 install on Amazon EC2 -- the AMI is ami-904f08c2. And I'm compiling the swf using Flex SDK 4.6 on Linux with the command "mxmlc -compiler.library-path+=./playerglobal11_0.swc -swf-version=13 -static-link-runtime-shared-libraries Broadcaster.as".
package {
import flash.display.MovieClip;
import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.events.MouseEvent;
import flash.events.AsyncErrorEvent;
import flash.net.NetStream;
import flash.media.Video;
import flash.media.Camera;
import flash.media.Microphone;
public class Broadcaster extends MovieClip {
private var nc:NetConnection;
private var ns:NetStream;
private var nsPlayer:NetStream;
private var vid:Video;
private var vidPlayer:Video;
private var cam:Camera;
private var mic:Microphone;
private var myMetadata:Object;
public function Broadcaster(){
setupUI();
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect("rtmp://myserver/live");
}
/*
* Clear the MetaData associated with the stream
*/
private function clearHandler(event:MouseEvent):void {
if (ns){
trace("Clearing MetaData");
ns.send("@clearDataFrame", "onMetaData");
}
}
private function startHandler(event:MouseEvent):void {
displayPlaybackVideo();
}
private function onNetStatus(event:NetStatusEvent):void {
trace(event.target + ": " + event.info.code);
switch (event.info.code)
{
case "NetConnection.Connect.Success":
publishCamera();
displayPublishingVideo();
break;
case "NetStream.Publish.Start":
sendMetadata();
break;
}
}
private function asyncErrorHandler(event:AsyncErrorEvent):void {
trace(event.text);
}
private function sendMetadata():void {
trace("sendMetaData() called")
myMetadata = new Object();
myMetadata.customProp = "Welcome to the Live feed of YOUR LIFE, already in progress.";
ns.send("@setDataFrame", "onMetaData", myMetadata);
}
private function publishCamera():void {
cam = Camera.getCamera();
mic = Microphone.getMicrophone();
ns = new NetStream(nc);
ns.client = this;
ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
ns.attachCamera(cam);
ns.attachAudio(mic);
ns.publish("livestream", "live");
}
private function displayPublishingVideo():void {
vid = new Video(cam.width, cam.height);
vid.x = 10;
vid.y = 10;
vid.attachCamera(cam);
addChild(vid);
}
private function displayPlaybackVideo():void {
nsPlayer = new NetStream(nc);
nsPlayer.client = this;
nsPlayer.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nsPlayer.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
nsPlayer.play("myCamera", 0);
vidPlayer = new Video(cam.width, cam.height);
vidPlayer.x = cam.width + 100;
vidPlayer.y = 10;
vidPlayer.attachNetStream(nsPlayer);
addChild(vidPlayer);
}
private function setupUI():void {
}
public function onMetaData(info:Object):void {
}
}
}
