Skip to main content
Known Participant
December 22, 2011
Answered

Why Stream.play() method do not work?

  • December 22, 2011
  • 1 reply
  • 3010 views

I want to create an application to switch streams and republish them as single continious stream to the remote server.

In first step I tested "livestreams code" from the "Example of Multipoint publishing" on p. 184 of the "ADOBE®FLASHMEDIA SERVER 4.5® Developer’s Guide" where ns.publish method is used. It was successful.

I try stream.play method now.

I had written main.asc code like in the Stream.play() example on p. 162 of the "Server-Side ACTIONSCRIPT® Language Reference for ADOBE® FLASH® MEDIASERVER 4.5", but I have some problem  in spite of this.

I try to broadcast to my local server (to URI - "localhost/studia") by two clients - by FMLE and  by my "livestreams" application consequently (with stream name "livestream2") and retraslate it to remote server using my application "studia" on local one.

The connection between two servers (with application "live") appears in the remote server Admin Consol,  but the stream from my local server do not come to it.

Here is my main.asc script:

application.myRemoteConn = new NetConnection();

application.myRemoteConn.onStatus = function(info){

    trace("Connect " + info.code + "\n");

    // Reply to all clients

    for (var i = 0; i < application.clients.length; i++){

        application.clients.call("onServerStatus", null, info.code, info.description);

    }

};

// Use NetConnection object to remote server connect (the remote server works with other application wery well)

application.myRemoteConn.connect("rtmp://RemoteServer/live");

// Server stream estimation

application.myStream = Stream.get("livestream");

application.myStream = Stream.get("livestream");

if (application.myStream){

application.myStream.play("livestream2", 0, -1, true, application.myRemoteConn);

}

Why Stream.play() method do not work?

What I do wrong?

This topic has been closed for replies.
Correct answer NpComplete

O.K., Thank you, but can I switch the streams - livestream1, livestream2, livestream3 etc. (that are broadcasted in parallel by number of clients to my local server)  for retranslation them consequently and continuously by ns.publish method? And What method I must to use for switching?

Tell me please!


In that case, I recommend you a mix of solution..

Something like this will be interesting to check:

var tempSwitchingStream = Stream.get("myswitchingstream"); // create a temp live stream on local server app..

tempSwitchingStream.play(livestream1, 0, -1);      // subscribe tempSwitching to livestream1.. i.e get content of livestream1 into it.. I may also switch to different streams into it..tempSwitchingStream will get content from the          //switched stream

if(tempSwitchingStream) // if it exist

{

        ns.attach(tempSwitchingStream);  // subscribe my net stream to recieve data from tempSwitchingStream

        ns.publish( livestream, "live" );  // now net stream is getting data from tempSwitchingStream, so publish that data with name "livestream" on the net connection.. Net stream already know about its NetConnection.. see above

}

Did you get the point?? I created a temp stream which may switch stream in its play method and then I am pushing this temp stream to remote server...

However this is little tricky.. Majorly, in most case similar to yours, people write applications on the remote server application to pull the stream and there switch the pulled stream in play method as described in first discussed method..

1 reply

Adobe Employee
December 22, 2011

This should be fine, but as per your code as I understand

You have a server -> "RemoteServer" which has application "live"

There is a stream being published on "RemoteServer" app "live" named "livestream2" from some source (may be FMLE)

and you are trying to pull the "livestream2" application to this server (where this script is hosted) from "RemoteServer" and play into the the "livestream" which will be on this server (where this application is hosted)..

Right??

So if There are server A and B.. A has application "live" and a stream "1" is being published on it through FMLE.

Now if you want a application "re-live" on server B and which pulls stream "1" from "A" and publishes a stream "2"

You may write this code in application "re-live"

application.myRemoteConn = new NetConnection();

application.myRemoteConn.onStatus = function(info){

    trace("Connect " + info.code + "\n");

    // Reply to all clients

    for (var i = 0; i < application.clients.length; i++){

        application.clients.call("onServerStatus", null, info.code, info.description);

    }

};

// Use NetConnection object to remote server connect (the remote server works with other application wery well)

application.myRemoteConn.connect("rtmp://A/live");

// Server stream estimation

application.myStream = Stream.get("2");

if (application.myStream){

application.myStream.play("1", 0, -1, true, application.myRemoteConn);

}

Hope it helps

Known Participant
December 22, 2011

I want to clarify (excuse me that I wrote so vague):

This script is in the my local host.

I broadcast from FMLE livestream2 to application "studia" on the local host and I want retranslate the stream named livestream2 by this script (main.asc file in the application/studia folder in the local server) to the application "live" on remote server.

Adobe Employee
December 22, 2011

Ok , so the above method was basically for the "pulling/proxying" the stream from the some remote server to our local server..

As I understand by your clarification, you want to "push/retranslate" the stream from local server to the remote server...

In that case, you need to multi-point publish..

    

application.myRemoteConn = new NetConnection();

application.myRemoteConn.onStatus = function(info){

    trace("Connect " + info.code + "\n");

    // Reply to all clients

    for (var i = 0; i < application.clients.length; i++){

        application.clients.call("onServerStatus", null, info.code, info.description);

    }

};

application.myRemoteConn.connect("rtmp://A/live");

   ns = new NetStream(application.myRemoteConn);  // create a netstream which will retranslate stream of my choice to this net connection.

        // called when the server NetStream object has a status

        ns.onStatus = function(info) {

            trace("Stream Status: " + info.code)

            if (info.code == "NetStream.Publish.Start") {

                trace("The stream is now publishing");

            }          

        }

        ns.setBufferTime(2);

  application.myStream = Stream.get("livestream2"); // get the object of livestream2 being published on this app

if(application.myStream) // if it exist

{

        ns.attach(application.myStream);  // subscribe my net stream to recieve data from livestream2

        ns.publish( livestream, "live" );  // now net stream is getting data from livestream2, so publish that data with name "livestream" on the net connection.. Net stream already know about its NetConnection.. see above

}