There are situations where it is necessary to call a server side method on FMS. Some CDNs, for example Limelight, used to or maybe still do require you to call the FCSubscribe method in order to request a live stream. This send a signals to the Edge server to pull the live stream from the Origin server if it is not already being delivered to that Edge. While this delivery method and stream setup routine is being phased out across most CDNs I thought it may be useful to post a (slightly hackish) workaround to make this setup work with the FLVPlayback component.
The problem with the FLVPlayback component is that there is no obvious, simple way to obtain a reference to the NetConnection Object it uses under the hood. Sure, the ncMgr.getNetConnection let's you grab it but only once the connection is established, and while you can implement a custom NCManager class, this is not trivial and after all a NetConnection is being maintained already by the component, so why reinvent the wheel?
The following code is clearly not something I am proud of, but it worked at the time when I needed it. It was used to get a live stream working with the FLVPlayback component streaming from Limelight about a year or two ago.
2 player.addEventListener("playing", playListener);
3 player.addEventListener("stateChange", stateListener);
4 player.addEventListener("ready", readyListener);
5
6/* this is the hack: check once every frame if the NC has been defined inside the FLVPlayback component */
7 this.onEnterFrame = function()
8 {
9 if (player.ncMgr.getNetConnection() != undefined)
10 {
11 this.onEnterFrame = null;
12 delete this.onEnterFrame;
13 trace("got NC");
14 //subscribe(streamName);
15 }
16 }
17
18 var nc:NetConnection;
19 var serverName:String = "server.llnwd.net";
20 var appName:String = "account_name/_definst_";
21 var streamName:String = "live";
22
23 var source_Str = "rtmp://" + serverName + "/" + appName + "/" + streamName;
24
25 // start up by setting the contentPath (now called source in newer versions of the component)
26
27player.contentPath = source_Str;
28
29 function subscribe(name:String)
30 {
31 nc = player.ncMgr.getNetConnection();
32
33 nc.onFCSubscribe = function(info:Object)
34 {
35 trace("onFCSubscribe: " + info.code);
36 clearInterval(int_id);
37
38 if (info.code == "NetStream.Play.StreamNotFound")
39 {
40 // handle error, retry after a few secs or similar
41 }
42 else if (info.code == "NetStream.Play.Start")
43 {
44 // we're successfully subscribed
45 }
46 else
47 {
48 // handle error
49 }
50 };
51
52
53// not used right now
54
55nc.onFCUnsubscribe = function(info:Object)
56 {
57 }
58
59 trace("subscribing to " + name);
60 nc.call("FCSubscribe",null,name);
61 }
62
63 // can be used to unsubscribe from stream
64
65function unsubscribe(name:String)
66 {
67 nc.call("FCUnsubscribe",null,name);
68 }
Hopefully this is helpful to someone.

#1 by Robert on 8/14/09 - 8:26 PM
Have you ever seen someone live stream using the Video object? I see tons of VOD with it but can't seem to find an example of live streaming. It must be possible.
#2 by Stefan Richter on 8/14/09 - 10:04 PM
I've seen video object used in both Flash and Flex a lot. I personally don't use the video display comp in Flex at all.
#3 by Ramon Roche on 8/15/09 - 2:18 AM
#4 by Robert on 8/15/09 - 2:35 AM
Any functioning snippets you have would be greatly appreciated.
#5 by walter Vargas on 8/24/09 - 2:21 PM
#6 by AdobeDocs on 8/25/09 - 9:35 PM
http://help.adobe.com/en_US/FlashMediaServer/3.5_D...
#7 by paul on 5/24/11 - 12:26 AM
I've got a temporary Edgecast CDN live stream here:
rtmp://fml.14CB.edgecastcdn.net/2014CB/live.flv
I have an instance of the FLVPlayback component on the stage with an instance name of "player," with the following code attached to the first frame of the timeline:
*********************
// listen to player events and kill manual connection once we're streaming
player.addEventListener("playing", playListener);
player.addEventListener("stateChange", stateListener);
player.addEventListener("ready", readyListener);
player.autoPlay = true;
player.isLive = true;
// this is the hack: check once every frame if the NC has been defined inside the FLVPlayback component
this.onEnterFrame = function() {
if (player.ncMgr.getNetConnection() != undefined) {
this.onEnterFrame = null;
delete this.onEnterFrame;
trace("got NC");
subscribe(streamName);
}
}
var nc:NetConnection;
var serverName:String = "fml.14CB.edgecastcdn.net";
var appName:String = "2014CB";
var streamName:String = "live.flv";
var source_Str = "rtmp://" + serverName + "/" + appName + "/" + streamName;
// start up by setting the contentPath (now called source in newer versions of the component)
player.contentPath = source_Str;
//trace(source_Str);
function subscribe(name:String) {
nc = player.ncMgr.getNetConnection();
nc.onFCSubscribe = function(info:Object) {
trace("onFCSubscribe: " + info.code);
clearInterval(int_id);
if (info.code == "NetStream.Play.StreamNotFound") {
// handle error, retry after a few secs or similar
} else if (info.code == "NetStream.Play.Start") {
// we're successfully subscribed
} else {
// handle error
}
}
nc.onFCUnsubscribe = function(info:Object) {
// not used right now
}
trace("subscribing to " + name);
nc.call("FCSubscribe", null, name);
}
// can be used to unsubscribe from stream
function unsubscribe(name:String) {
nc.call("FCUnsubscribe", null, name);
}
*********************
I'm getting the following Output when I test my movie:
got NC
subscribing to live.flv
onFCSubscribe: NetStream.Play.Start
I feel like I should be putting something where the
"we're successfully subscribed" comment is but I don't know what that *something* should be. I've tried a variety of player.play() actions and whatnot but I'm just stabbing in the dark.
Any help is greatly appreciated.
#8 by Stefan Richter on 5/24/11 - 8:23 AM
function subscribe(name:String)
{
nc = player.ncMgr.getNetConnection();
nc.onFCSubscribe = function(info:Object)
{
clearInterval(int_id);
if (info.code == "NetStream.Play.StreamNotFound")
{
// stream failed, try stream 2
source_Str = conn_Str + "/" + streamName2;
// reconnect player's netconnection
player.ncMgr.reconnect();
// set player source to new stream
player.contentPath = source_Str;
// try second stream after a short wait
int_id = setInterval(subscribe, 2500, streamName2);
}
else if (info.code == "NetStream.Play.Start")
{
// we're successfully subscribed
}
else
{
// handle error
}
};
// not in use atm
nc.onFCUnsubscribe = function(info:Object)
{
// do something
}
nc.call("FCSubscribe",null,name);
}
I think you have an error right at the top of your code:
var streamName:String = "live.flv";
A live stream does not normally carry a file extension and the FLVPlayback component may get 'confused' by it, tying to play a recorded flv instead. My own player which works fine using a near identical logic to yours but it uses a stream name without file extension.
var streamName:String = "livestream";
Hope this helps.
#9 by paul on 5/24/11 - 8:37 PM
I'll see if there's a way to remove the extension and see if that resolves the issue.
#10 by Stefan Richter on 5/24/11 - 9:00 PM
what do you mean by see if there's way to remove it? You posted some sources above, can't you simply take the .flv away and recompile? Or am I missing something?
#11 by paul on 5/25/11 - 12:32 AM
Sure, I can type it into the code as just "live" but it doesn't yield any different results.
The JW Player (which is unfortunately not an option) accepts and plays the live.flv feed ok. This is a perplexing puzzle.
#12 by Stefan Richter on 5/25/11 - 9:03 AM
You mean it's named live.flv if it gets recorded?
The server does not alter the live stream name as entered in FMLE. If your stream is named 'live' at the encoder then the live stream you subscribe to in Flash would also be 'live', not 'live.flv'.