Copy link to clipboard
Copied
I want to measure the time a file is loaded from a remote directory.
I wrote the code as below, but I don't trust it.
Please let me know if there are any problems and ask for better sample code.
function musicPlay(url: String): void {
if (channel) { channel.stop(); }
url = "http://....................mp3";
sound = new Sound(new URLRequest(url));
channel = new SoundChannel();
sound.addEventListener(ProgressEvent.PROGRESS, progressHandler);
sound.addEventListener(Event.COMPLETE, loadCompleteHandler);
channel = sound.play(0);
}
var beginTime: Number = 0;
var endTime: Number = 0;
function progressHandler(e: ProgressEvent): void {
var aDate: Date = new Date();
if (e.bytesLoaded == 0) {
beginTime = aDate.valueOf();
}
if (e.bytesLoaded == e.bytesTotal) {
var zDate: Date = new Date();
endTime = zDate.valueOf();
var passedTime: Number = (endTime-beginTime)/1000;
trace("Loaded Speed : " + passedTime + "/s");
}
}
function loadCompleteHandler(e: Event): void {
//...............................................
}
Have something to add?