loading bar problem for multiple sounds loaded

Contributor ,
Jan 26, 2022 Jan 26, 2022

Copy link to clipboard

Copied

Hello. I am loading multiple mp3 sounds with a loading bar. they load fine, but the problem is that during loading the bar does not advance and only advances at full speed at the end (as if it only works with the last sound) I have tried putting large files and the same thing happens, it takes longer to load and only you see the bar at the end at full speed. (barely visible).

Thanks for the help. this is the code

public class Standars_all_mc extends MovieClip {


		private var sound0:Sound = new Sound();
		private var sound1:Sound = new Sound();
		private var sound2:Sound = new Sound();
		private var sound3:Sound = new Sound();
		private var sound4:Sound = new Sound();
		private var sound5:Sound = new Sound();
		private var sound6:Sound = new Sound();
		private var sound7:Sound = new Sound();
		private var sound8:Sound = new Sound();
		private var sound9:Sound = new Sound();
		private var sound10:Sound = new Sound();
		private var sound11:Sound = new Sound();
		private var sound12:Sound = new Sound();
etc...................
		
		private var soundA:Array = ["sound0","sound1","sound2"];
		private var soundB:Array = ["sound3","sound4","sound5"];
etc.........................
		
		private var soundZ:Array = ["sound0","sound1","sound2","sound3","sound4","sound5","sound6","sound7","sound8","sound9","sound10","sound11","sound12","sound13","sound14","sound15","sound16","sound17","sound18","sound19","sound20","sound21","sound22","sound23","sound24","sound25","sound26","sound27","sound28","sound29","sound30","sound31","sound32","sound33","sound34","sound35","sound36","sound37","sound38","sound39","sound40","sound41","sound42","sound43","sound44","sound45","sound46","sound47","sound48","sound49","sound50","sound51","sound52","sound53"];

		private var i:int;
		//soundA
		var Bergamasca0:String = "https://drive.google.com/uc?id=1Y36t7fLgRHqQ4XLZajC5VHSYuhLM1FKV&export=download";
		var Bergamasca1:String = "https://drive.google.com/uc?id=1P4WDhtAm3XCnG1wcNObCKXFy00wE83Vz&export=download";
		var Bergamasca2:String = "https://drive.google.com/uc?id=1ihNAVa82jGkr973tfpre1wf3zdT3kPR1&export=download";
		//soundB
		var Bergamasca3:String = "https://drive.google.com/uc?id=1IDv5pTbh94GT_dqocQuSZqfQH1CtysNR&export=download";
		var Bergamasca4:String = "https://drive.google.com/uc?id=1MKkj30XSC_Is-jWYKqnb2KVVIBZqa0Kg&export=download";
		var Bergamasca5:String = "https://drive.google.com/uc?id=1eOzms1xf_Do0FSYmNciC1gSnG2I5Oh0A&export=download";
		//soundC
		var Bergamasca6:String = "https://drive.google.com/uc?id=1r4z6r4dw0Yv3Ljuxm4Qomx6IsQHC2Flv&export=download";
		var Bergamasca7:String = "https://drive.google.com/uc?id=145j8Vj8H7Z1fUuD5g03-KlwyAe7RN2Wy&export=download";
		var Bergamasca8:String = "https://drive.google.com/uc?id=16zGvRdTK6fvzBM3PmYrKSXKtQFQC6saD&export=download";
		//soundD
etc................................
		
		public function Standars_all_mc() {
			this.addEventListener(Event.ADDED_TO_STAGE,addedF);
		}
		
		private function addedF(e:Event):void{
			//if(!back_mc.hasEventListener(MouseEvent.MOUSE_DOWN)){
					
			load_soundsF();
			}
//carga de sonidos
		
		private function load_soundsF():void {
			
			//bar
			controlCarga.width = 320;
			controlCarga.height = 7;
			addChild (controlCarga);
			controlCarga.move((width/2)-320,height/2);
			pantallaCarga.gotoAndStop(2);

			//sounds charge
			for (var i:uint=0; i<54; i++) {
				this[soundZ[i]] = new Sound();
				this[soundZ[i]].load (new URLRequest(this[Data.so.data.sound+i]));
				controlCarga.source = this[soundZ[i]];
				controlCarga.addEventListener(ProgressEvent.PROGRESS, imagenProgreso);
				controlCarga.addEventListener(IOErrorEvent.IO_ERROR, onError);
				controlCarga.addEventListener(Event.COMPLETE, imagenCargada);
			}
			function imagenProgreso(event:ProgressEvent):void {
				//pantallaCarga.formato_1.text = "Cargando" + Data.so.data["sound"].split("_").join(" ")+".......";
				//"Load..." + Math.floor(event.bytesLoaded / 1024) + "/" + Math.floor(event.bytesTotal / 1024) + "KB";
				//trace("progressHandler: bytesLoaded=" + e.bytesLoaded + " bytesTotal=" + e.bytesTotal);
			}

			function imagenCargada(event:Event):void {
				pantallaCarga.formato_1.text = Data.so.data["sound"].split("_").join(" ")+" cargado con exito";
				pantallaCarga.gotoAndPlay(3);

				if (contains (controlCarga)){
					removeChild (controlCarga);
				}
			}

			function onError(event:IOErrorEvent):void {
				trace("ioErrorHandler");
				//pantallaCarga.play();
				dispatchEvent(backE);
			}
		}

 

Views

269

Likes

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
Adobe Community Professional ,
Jan 26, 2022 Jan 26, 2022

Copy link to clipboard

Copied

your load progress bar is only showing the load progress of one sound

this[Data.so.data.sound+53]

 

and with your approach you need multiple (54) load progress listeners and then you can estimate the load progress and the group by advancing 1/54th per sound load.

Likes

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
Contributor ,
Jan 26, 2022 Jan 26, 2022

Copy link to clipboard

Copied

Hello. I have changed the listener line

controlCarga.addEventListener(ProgressEvent.PROGRESS, imagenProgreso);


for

This other

this[soundZ[i]].addEventListener(ProgressEvent.PROGRESS, imagenProgreso);

 

the result remains the same.

thanks for the help

 

Likes

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
Adobe Community Professional ,
Jan 26, 2022 Jan 26, 2022

Copy link to clipboard

Copied

if you're doing that in the same for-loop, you'll have the same problem and can expect the same result.

 

load them sequentially and update your load bar (and load the next sound until all sounds have been loaded).

Likes

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
Contributor ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

The truth is that I do not understand the procedure well. with the loop the sounds are supposed to be loaded sequentially. What doesn't seem to work with the loop is the loading bar update. These lines that updates the loading bar

controlCarga.source = this[soundZ[i]];

this[soundZ[i]].addEventListener(ProgressEvent.PROGRESS, imagenProgreso);

they don't seem to work...could you give me some hint in the form of code? (perhaps only the first load).
Many thanks

Likes

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
Adobe Community Professional ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

var current_index=0;

loadNextF();

 

function loadNextF():void{

var i:int = current_index;

this[soundZ[i]] = new Sound();
this[soundZ[i]].load (new URLRequest(this[Data.so.data.sound+i]));
controlCarga.source = this[soundZ[i]];
controlCarga.addEventListener(IOErrorEvent.IO_ERROR, onError);
controlCarga.addEventListener(Event.COMPLETE, imagenCargada);

}

 

function imagenCargada():void{

// load progress has advanced another 1/54th. update your loadbar.

current_index++;

if(current_index<54){

loadNextF();

} else {

// loading complete. do whatever.

}

}

 

 

 

 

Likes

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
Contributor ,
Feb 05, 2022 Feb 05, 2022

Copy link to clipboard

Copied

Hello. Sorry for the delay. The way proposed in the last answer, makes the load much slower, so I'm not interested. It also has the problem that the loading bar does not load once for all the sounds, but instead loads 53 times for the 53 sounds, which does not help much to know when the load ends. It helps to know if there is an error in an intermediate load and that's where I'm investigating. Thank you very much for the code and for the help.

Likes

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
Adobe Community Professional ,
Feb 05, 2022 Feb 05, 2022

Copy link to clipboard

Copied

then you're doing something wrong.

Likes

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
Contributor ,
Feb 06, 2022 Feb 06, 2022

Copy link to clipboard

Copied

Hello!. I have tried again in a thousand ways and the result is always the same: the bar loads several 53 times and the load is very slow. I send my code. I have corrected very little (the function imagenCargada was missing to put (event: event), I think).

Thank you very much for the help

 

 

public class Standars_all_mc extends MovieClip {
    private var i:int;
    private var current_index:int;


public function Standars_all_mc() {
	this.addEventListener(Event.ADDED_TO_STAGE,addedF);
}

private function addedF(e:Event):void{
    default_settingsF();
    loadNextF();
}
function loadNextF():void{
	i = current_index;
	this[soundZ[i]] = new Sound();
	this[soundZ[i]].load (new URLRequest(this[Data.so.data.sound+i]));
	controlCarga.source = this[soundZ[i]];
	controlCarga.addEventListener(Event.COMPLETE, imagenCargada);
}

function imagenCargada(event:Event):void{

// load progress has advanced another 1/54th. update your loadbar.
	current_index++;
	if(current_index<54){
		loadNextF();
	}
	else {
		pantallaCarga.formato_1.text = Data.so.data["sound"].split("_").join(" ")+" cargado con exito";
		pantallaCarga.gotoAndPlay(3);
		removeChild(controlCarga);
	}
}

private function default_settingsF():void{
	pantallaCarga.gotoAndStop(2);
	controlCarga.width = 320;
	controlCarga.height = 7;
	addChild (controlCarga);
	controlCarga.move((width/2)-320,height/2);
	pantallaCarga.gotoAndStop(2);
	current_index=0;
}
}	

 

 

Likes

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
Adobe Community Professional ,
Feb 06, 2022 Feb 06, 2022

Copy link to clipboard

Copied

you're not updating your loadbar.

 

imagenCargada(event:Event):void{


current_index++;
if(current_index<54){
loadNextF();

// load progress has advanced another 1/54th. update your loadbar. eg,

loadbar.progress.scaleX = current_index/54;


}
else {
pantallaCarga.formato_1.text = Data.so.data["sound"].split("_").join(" ")+" cargado con exito";
pantallaCarga.gotoAndPlay(3);
removeChild(controlCarga);
}

Likes

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
Contributor ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

Hello. I have tried adding what you told me. I have added this line:

 

controlCarga.scaleX = i/25;

 

 

indeed the bar rises progressively. Not the fill of the bar but the bar rise... If I put a transparent rectangle around it, the effect is achieved... but the loading is much slower (20 times slower, more or less), so I think I'm going to opt for a circle that goes around or something like that to entertain to the user while charging.

I also tried to use drop box direct links and the result is exactly the same.

Thank you very much for all the answers and we continue learning. Thanks!

.

 

 

 

function loadNextF():void{
	i = current_index;
	this[soundZ[i]] = new Sound();
	this[soundZ[i]].load (new URLRequest(this[Data.so.data.sound+i]));
	//controlCarga.source = this[soundZ[i]];
	controlCarga.scaleX = i/25;
	//controlCarga.width = 54;
	pantallaCarga.carga_text.text = "Cargando "+ Data.so.data["sound"].split("_").join(" ")+".......";
	//controlCarga.addEventListener(ProgressEvent.PROGRESS, imagenProgreso);
	//controlCarga.addEventListener(IOErrorEvent.IO_ERROR, onError);
	this[soundZ[i]].addEventListener(Event.COMPLETE, imagenCargada);
}

//function imagenProgreso(event:ProgressEvent):void {
	
//}
function imagenCargada(event:Event):void{

// load progress has advanced another 1/54th. update your loadbar.
	current_index++;
	//i++;
	if(current_index<54){
		loadNextF();
		//loadbar.progress.scaleX = current_index/54;
		//controlCarga.scaleX = current_index/54;
		
	}
	else {
		pantallaCarga.formato_1.text = Data.so.data["sound"].split("_").join(" ")+" cargado con exito";
		pantallaCarga.gotoAndPlay(3);
		removeChild(controlCarga);
	}

}

 

Likes

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
Adobe Community Professional ,
Feb 06, 2022 Feb 06, 2022

Copy link to clipboard

Copied

Hi.

 

I think the real problem is Google Drive. The links are not pointing directly to the sound files. There's some processing in the middle that prevents AS3 from getting any data as soon as the requests are made.

 

If you try to use a direct link to a sound file you'll see that the information about the file will be available immediately.

Likes

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
Contributor ,
Feb 06, 2022 Feb 06, 2022

Copy link to clipboard

Copied

I use the download link generator extension. This generates, a direct link is supposed...

Maybe it's not the right way...

 

this one (screen shot)

Likes

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
Adobe Community Professional ,
Feb 06, 2022 Feb 06, 2022

Copy link to clipboard

Copied

what makes you think that includes a load progress bar that needs no code?

Likes

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
Contributor ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

I tried with dropbox direct link and the result is the same

Likes

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
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

someone would probably need to download and fix your code/fla to get this working for you.

 

but it is doable. here's a website i developed in animate, index (tonyfostergraphicdesign.com)

 

if you click portfolio (or architectural), you'll see an image loading update.

Likes

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
Contributor ,
Feb 12, 2022 Feb 12, 2022

Copy link to clipboard

Copied

yes, it's fantastic!

 

Likes

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
Adobe Community Professional ,
Feb 12, 2022 Feb 12, 2022

Copy link to clipboard

Copied

did it help you solve your problem?

Likes

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
Contributor ,
Feb 14, 2022 Feb 14, 2022

Copy link to clipboard

Copied

The inputs of your code allow me to do a countdown, it also allows me to load a loading bar, but unfortunately the loading speed is very slow, so I have to look for other options. Thank you very much for the contributions!

Likes

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
Adobe Community Professional ,
Feb 14, 2022 Feb 14, 2022

Copy link to clipboard

Copied

you're welcome.

 

p.s. was the loading speed slow at the tonyfoster site?

Likes

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
Contributor ,
Feb 14, 2022 Feb 14, 2022

Copy link to clipboard

Copied

It didn't seem slow at all to me in your example.

 

the problem is that uploading the files with my code goes very fast (although it doesn't allow me to control the upload at all) and with your code the control is greater but it is very slow. There was a lot of difference between the two ways.

best regards!!

Likes

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
Adobe Community Professional ,
Feb 14, 2022 Feb 14, 2022

Copy link to clipboard

Copied

the loading code i suggested for you is similar to the code i used for tonyfoster, so it's about as fast as mass loading (at least, it is if you're loading less than 1000 files). 

Likes

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
Contributor ,
Feb 15, 2022 Feb 15, 2022

Copy link to clipboard

Copied

The loading of 53 short mp3 sounds (5 seconds each) with my initial code takes about 4 or 5 seconds. The load with your code (where I can go warning of the songs that are missing to load) (of the same songs) are 45 seconds!

 

I think it's too long

 

thanks for the help!

Likes

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
Adobe Community Professional ,
Feb 15, 2022 Feb 15, 2022

Copy link to clipboard

Copied

LATEST

you're welcome.

Likes

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