Skip to main content
Inspiring
January 26, 2022
Question

loading bar problem for multiple sounds loaded

  • January 26, 2022
  • 2 replies
  • 1726 views

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);
			}
		}

 

    This topic has been closed for replies.

    2 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    February 6, 2022

    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.

    Inspiring
    February 6, 2022

    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)

    kglad
    Community Expert
    Community Expert
    February 6, 2022

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

    kglad
    Community Expert
    Community Expert
    January 26, 2022

    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.

    Inspiring
    January 26, 2022

    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

     

    kglad
    Community Expert
    Community Expert
    January 27, 2022

    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).