Copy link to clipboard
Copied
when I user AMS/FMS server-side api "Stream".The documentation says that "Stream" can pull a stream from a remote server.But can not pull a stream from any remote server.Access to the local stream nothing.why?
Code:
var nc;
var myStream;
application.onAppStart = function(){
nc = new NetConnection();
myStream = Stream.get("localstream");
myStream.onStatus= function(info){
trace(info.code);
}
nc.onStatus = function(info){
trace (info.code);
if(info.code == "NetConnection.Connect.Success" ){
myStream.play("hks", -1, -1, true, nc);
}
}
nc.connect("rtmp://live.hkstv.hk.lxdns.com/live");
}
Copy link to clipboard
Copied
Can you explain what are you trying to accomplish. If you want to ingest a local stream to remote machine...here is the sample code.
var TARGET_URL | = "rtmp://my.remoteserver.com/test" | |
var TARGET_STREAM | = "mp4:recordStream.f4v" |
var nc;
var ns;
var BUFFER_LENGTH = 4;
var DUMMY_STREAM_NAME = "sample.flv"
var isConnectionValid = -1;
var context = { id : -1, streamObj: null }
function NetStream_onStatus(info)
{
trace(">>> NetStream.onStatus(): " + info.code); | ||
if (info.code == "NetStream.Publish.Start") | ||
{ | ||
trace("The stream is now publishing"); | ||
} |
}
function NetConnection_onStatus(info)
{
trace(">>> NetConnection.onStatus(): " + info.code); | ||
switch(info.code) | ||
{ | ||
case "NetConnection.Connect.Success" : | ||
{ | ||
isConnectionValid = 1; | ||
trace("Target connection to URL: " + TARGET_URL + " succesfull!."); | ||
break; | ||
} | ||
default : | ||
{ | ||
trace("Error in connecting to URL: " + TARGET_URL); | ||
isConnectionValid = 0; | ||
break; | ||
} | ||
} |
}
Client.prototype.FCPublish = function(stream_name)
{
// This is also called but only by FMLE |
}
Client.prototype.FCUnpublish = function(stream_name)
{
// This is also called but only by FMLE |
}
Client.prototype.releaseStream = function(stream_name)
{
// This is also called but only by FMLE |
}
function myProcessRemote(isValidConnection, streamObj)
{
if(isValidConnection) | ||
{ | ||
ns = new NetStream(nc); | ||
// called when the server NetStream object has a status | ||
ns.onStatus = NetStream_onStatus; | ||
ns.setBufferTime(BUFFER_LENGTH); | ||
// | var dummyStream = Stream.get(DUMMY_STREAM_NAME); | |
ns.attach(streamObj); | ||
ns.publish(TARGET_STREAM, "record"); | ||
} |
}
function myWaitForRemoteConnection(context)
{
if(isConnectionValid != -1) | |||
{ | |||
clearInterval(context.id); | |||
delete context.id; | |||
context.id = -1; | |||
if(isConnectionValid == 1) | |||
myProcessRemote(true, context.streamObj); | |||
else | |||
myProcessRemote(false, context.streamObj); | |||
} |
}
application.onPublish = function(client,myStream)
{
nc = new NetConnection(); | |||
nc.onStatus = NetConnection_onStatus; | |||
nc.connect(TARGET_URL); | |||
if(isConnectionValid == -1) | |||
{ | |||
context.streamObj = myStream; | |||
context.id = setInterval(myWaitForRemoteConnection, 5000, context); | |||
} | |||
else | |||
{ | |||
if(isConnectionValid == 1) | |||
{ | |||
myProcessRemote(true, myStream); | |||
} | |||
else | |||
{ | |||
myProcessRemote(false, myStream); | |||
} | |||
} |
}
application.onUnpublish = function(client,myStream)
{
if(isConnectionValid == 1) | ||
{ | ||
ns.publish(false); | ||
delete ns; | ||
ns = null; | ||
nc.close(); | ||
delete nc; | ||
nc=null; | ||
isConnectionValid = -1; | ||
} |
}
application.onAppStart = function()
{
trace("Welcome to " + application.server); | |
trace("Application name: " + application.name); |
}
application.onAppShutdown = function()
{
trace("Terminating " + application.name); |
}