View comments | RSS feed

Getting the stream time length with ActionScript

If you are buffering your streams, you can use the NetStream.bufferLength property to get the number of seconds currently in the buffer. Sometimes, however, you may want to get the total length of a stream. Flash Player doesn't have this information, but Flash Media Server does; the server has a Stream.length property that the client can request through a message to the server.

You can use client-side ActionScript such as the following to request the stream length:

function getInfo(){
    nc.call("sendInfo", new MyResultSetName(), myStream);
}
function MyResultSetName(){
    this.onResult = function(retVal){
        _root.streamlength = retVal;
    };
    this.onStatus = function(info){
        trace("Level: " + info.level + "   Code: " +  info.code);
        // process error object
    };
}

Then, in the corresponding server-side ActionScript, you would add the following code in the main.asc file:

application.onAppStart = function(){
    trace("::: Application has started :::");
}
application.onConnect = function(client){
    application.acceptConnection(client);
    // Add methods
    client.prototype.sendInfo = function(name) {
        var slen = Stream.length(name);
        trace("slen: " + slen);
        return slen;
    };
}

Comments


Craig Grummitt said on Oct 3, 2006 at 6:28 PM :
I receive the error "TypeError: client.prototype has no properties" with the above server-side script. It seems to work when i remove the word prototype.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/fms/2/docs/00000065.html