• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

AS3, file load time measurement

Explorer ,
Aug 01, 2023 Aug 01, 2023

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 {
	//...............................................
}

 

 

Views

51

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation