Skip to main content
Participant
Mar 4, 2009 5:39 PM UTC
Question

MP3 - getStreamLength - using a virtual path help needed !

Hi to all,

I am trying to get the Stream.length of an MP3 file type but using also a virtual path that is assigned to the Vhost.XML.
After many tries i only manage to make it work only if the MP3`s are sitting inside the FMS_root_directory_applications_myMusicApp into a folder with the name "streams" wherever else i use the code that i am writing below it returns "0 seconds" as the Stream.length of every MP3.

In the main.asc i use this code :
application.onConnect = function(newClient, userObject, name){
if(userObject.userType == "Test_Music"){
newClient.virtualKey = "Music";
newClient.name = name;

newClient.getTheLength = function(streamName) {
trace("The "+streamName+" Total Time is "+Stream.length(streamName)+" : seconds");
return Stream.length(streamName);
}

}

application.acceptConnection(newClient);
}

In the Fla. file i use this to get the length:
var V_Path:String = "Music/";
var TheSound:String = "MyMp3";

var streamName:String = "mp3:"+V_Path+TheSound;

nc.call("getTheLength", { onResult: Delegate.create(this, setDuration) }, streamName);

function setDuration(nLength:Number):Void {
trace(nLength + " seconds");
}

Everything is streaming, everything works well, but i can`t get the StreamLength thou i can stream the MP3 from a virtual path

Any help would be appreciated, i have tried many times with diferent ways and nothing returns me what i need !

Thanx in advance
    This topic is closed to new replies. Start a new post to keep the conversation going.

    2 replies

    kaziris_Author
    Participant
    Mar 5, 2009 11:08 AM UTC
    Thanx for the interest but i have solved it .

    For anyone that will stuck in this kind of problem such as Streaming Mp3 using a virtual Directory and also a virtual key in Vhost.xml (e.x. <Streams key="Music">Music;C:\myFolder\Mymusic</Streams>)
    you should consider to remove the "virtual key" cause you can`t get the Stream.length

    In the main.asc i was using this code :
    application.onConnect = function(newClient, userObject, name){
    if(userObject.userType == "Test_Music"){
    newClient.virtualKey = "Music"; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< THIS IS THE PROBLEM TO GET THE STREAM LENGTH
    newClient.name = name;

    newClient.getTheLength = function(streamName) {
    trace("The "+streamName+" Total Time is "+Stream.length(streamName)+" : seconds");
    return Stream.length(streamName);
    }

    }

    So all you have to do is to remove the virtualKey from the Client.Object and from the Vhost.XML

    Thanx for your time FlashConference

    Translate
    Participant
    Mar 5, 2009 8:58 AM UTC
    umm...
    first understand me.. because I'm not use english language.. my language is korea language I'm Korean.. so my english is very poor..i'm sorry..

    I think .. your code is as2 . right?

    I make the sample file for kaziris_.
    sample code is as3

    first you make the application folder in applications (ex. applications\c)

    if you test this sample code that you need You_call_it_love.mp3 file in vod\media
    I hope your success! (adambrothers@gmail.com)

    //flash code(*.fla)
    var nc:NetConnection = new NetConnection();
    nc.connect("rtmp://localhost/vod");
    nc.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
    nc.client = this;
    var ns:NetStream;
    function statusHandler(e:NetStatusEvent):void
    {
    trace("e.info.code = "+e.info.code);
    if (e.info.code=="NetConnection.Connect.Success")
    {
    ns = new NetStream(nc);
    var songName:String = "mp3:You_call_it_love";
    ns.play(songName);
    var responder = new Responder(resultHandler);
    nc.call("getStreamLength", responder, songName);
    }
    }

    function resultHandler(songTotalTimeLine):void
    {
    trace("songTotalTimeLine : "+songTotalTimeLine);
    }

    // asc code(main.asc)
    application.onConnect = function(client)
    {
    client.getStreamLength = function( streamName ) {
    trace("length is " + Stream.length( streamName ));
    return Stream.length( streamName );
    }
    application.acceptConnection(client);
    }

    Translate