So I've been impressed with FMIS 3.5, up until now, and I'm really hoping somebody can set me on the right track here...
I've written a simple video player with a scrubbable playhead and the whole 9, but I can't seem to write an audio player. I can play the audio, and get id3 tag information, but for the life of me I can't get the length of an mp3 file!
I work at an educational institution, and we're streaming 15 minute sound files, so they have to be streamed, I can't use the Sound class. I've tried writing the server code for Stream.length, but I just can't seem to get the client to communicate, and as I work though it, I'm seeing more and more messages that Stream.length doesn't return an accurate stream length, which won't work at all...
I'm assuming there are audio players out there streaming mp3 files from FMIS, so there's gotta be a way to do it, but I'm just not seeing it.
Can somebody lend a hand, please?
Thanks!
Comments
So after posting this question, through some work and research I was able to find the answer. I don't know how often I'll be back by this posting again, so I hope that this response to my question makes sense for those who come across it in the future...
First, an explanation of how I am implementing FMIS 3.5. I work for a school, so we have loads of media to stream. I've set up a separate application (directory) for each course we offer. So a typical structure may look like:
\applications\spa101\streams\_definst_
The spa101 folder has a main.asc file in it. This is the file that controls the communicaton between FMIS and the client. The code in my main.asc file looks like...
application.onConnect = function( client ) {
client.getStreamLength = function( streamName ) {
return Stream.length( streamName );
}
application.acceptConnection( client );
}
And that's it. This code does 2 things. It defines a getStreamLength function, and takes the parameter "streamName", then returns the length of that stream. Next it accepts the connection (which is standard with every main.asc file that I've ever seen).
Basically it boils down to the fact that to get the length of an mp3 file with FMIS 3.5, you need to call Stream.length(); from the main.asc file that is in your application's folder on the server, there is no way to get the length of the stream from the client.
To communicate with your applications's main.asc file, you need to set up a Responder:
var responder:Responder = new Responder(onResult);
This sets up the responder, and uses an onResult function that I've defined later. You'll also need to use NetConnection.call...
responder = new Responder(onResult);
theNetConnection.call("getStreamLength", responder, whichSound);
I've set up a variable named "theNetConnection" to point to my NetConnection. So I'm calling the function "getStreamLength" (which is in quotes), sending the response to my responder, and sending the variable "whichSound" which is the sound that I'm attempting to play.
The main.asc file sees that I'm calling the getStreamLength function, and so it returns the length of the mp3 file. The following onResult function does what I need to with the result sent back to me...
function onResult(result:Object) {
trace("the stream length is " + result);
theStreamLength = result;
var theTotalTime:Number = theStreamLength;
player_mc.totalTime_txt.text = secondsConverter(theTotalTime);
}
This function gets the result, and assigns it to a varibale named "theStreamLength". I then convert that to a number variable named "theTotalTime", and use a secondsConverter function to display the time in correct time format, as opposed to a total number of seconds. Here's that function, just to include it...
function secondsConverter(sec:Number):String
{
var h:Number=Math.floor(sec/3600);
var m:Number=Math.floor((sec%3600)/60);
var s:Number=Math.floor((sec%3600)%60);
return(h==0?"":(h<10?"0"+h.toString()+":":h.toString()+":"))+(m<10?""+m.toString():m.toString())+":"+(s<10?"0"+s.toString():s.toString());
}
So I hope this helps somebody with the same quesiton that I had...