Skip to content

Instantly share code, notes, and snippets.

@HenningM
Created June 20, 2014 13:04
Show Gist options
  • Save HenningM/96e35a44de4eecdc1fdc to your computer and use it in GitHub Desktop.
Save HenningM/96e35a44de4eecdc1fdc to your computer and use it in GitHub Desktop.
Internap FCSubscribe example
package {
import flash.display.Sprite;
import flash.events.EventDispatcher;
import flash.events.NetStatusEvent;
import flash.events.AsyncErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.Event;
public class BasicLiveVideo extends Sprite
{
public var hostName:String = "rtmp://client.flash.internapcdn.net/client/live_1";
public var streamName:String = "thestream";
public var netConnection:NetConnection;
public var netStream:NetStream;
public var video:Video;
public function BasicLiveVideo()
{
video = new Video();
this.addChild(video);
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
var rtnClient:Object = new Object();
rtnClient.onFCSubscribe = function (info:Object){
netStream.play(streamName);
video.attachNetStream(netStream);
}
rtnClient.onFCUnsubscribe = function (info:Object){
netStream.close();
}
netConnection.client = rtnClient;
netConnection.connect(hostName);
}
public function netStatusHandler(nse:NetStatusEvent):void
{
trace ("NetStatus: " + nse.info.code);
switch (nse.info.code) {
case "NetConnection.Connect.Success":
netStream = new NetStream(netConnection);
netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, AsyncErrorCall);
var nsClient:Object = new Object();
nsClient.onMetaData = function (info)
{
trace ("onMetaData return:");
for (var prop:Object in info){
trace (" {" + prop.toString() + " = " + info[prop]+ "}");
}
}
// Note onFI appears to be a function of FMS, this is here to remove the callback error.
nsClient.onFI = function (info){
// No Op
}
netStream.client = nsClient;
netConnection.call("FCSubscribe", null, streamName);
trace ("called...");
break;
default:
trace("Error with NetConnection");
break;
}
}
public function AsyncErrorCall(ase:AsyncErrorEvent):void{
trace ("onAsyncError:" + ase.error.message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment