Skip to main content
Inspiring
June 6, 2021
Answered

loading bar for mp3 sound

  • June 6, 2021
  • 1 reply
  • 526 views

Good Morning. I'm trying to make a loading bar, for a sound in the cloud or mp3, with a text that indicates the amount of kb loaded. two things happen to me:

- the bar remains blank but does not advance ... remains blank while loading
- the total kb does not come out, it comes out "0"

Thank you very much for the time and help.

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi.

     

    Thanks for the code.

     

    The problem is in the MP3 URL. You should use a direct link to your MP3 file. This Google Drive links actually redirects to the actual MP3 file.

     

    To get the progress bar working set its source property to the sound instance. Like this:

    import fl.controls.ProgressBar;
    
    var audio: Sound = new Sound();
    var controlCarga: ProgressBar = new ProgressBar();
    
    function onProgress(event: ProgressEvent): void
    {
    	formato.text = "Load..." + Math.floor(event.bytesLoaded / 1024) + "/" + Math.floor(event.bytesTotal / 1024) + "KB";
    }
    
    function onComplete(e: Event): void
    {
    	formato.text = "archivo cargado con éxito";
    	audio.play();
    	removeChild(controlCarga);
    }
    
    //audio.load(new URLRequest("https://drive.google.com/uc?id=10NdOk1E5gvyzbv98svIGo_bDY5Nea5ZZ&export=download"));
    audio.load(new URLRequest("YOUR_DIRECT_URL_TO_YOUR_MP3_FILE.mp3"));
    audio.addEventListener(Event.COMPLETE, onComplete);
    audio.addEventListener(ProgressEvent.PROGRESS, onProgress);
    
    controlCarga.source = audio;
    controlCarga.width = 320;
    controlCarga.move(50, 40);
    addChild(controlCarga);

     

    Regards,

    JC

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    June 6, 2021

    Hi.

     

    HTML5 or AS3?

     

    And can you provide details/code about the situtation you're loading the MP3?

     

    Regards,

    JC

    Inspiring
    June 6, 2021

    as3

    sorry...I forgot it....

    var audio:Sound = new Sound();
    
    var controlCarga:ProgressBar = new ProgressBar();
    controlCarga.source = this.loaderInfo;
    controlCarga.width =320;
    controlCarga.move (50,40);
    
    audio.load (new URLRequest (" https://drive.google.com/uc?id=10NdOk1E5gvyzbv98svIGo_bDY5Nea5ZZ&export=download"));
    addChild (controlCarga);
    audio.addEventListener (Event.COMPLETE, onComplete);
    audio.addEventListener (ProgressEvent.PROGRESS, onProgress);
    
    
    function onProgress (event:ProgressEvent):void{
    
    	formato.text = "Load..." + Math.floor (event.bytesLoaded/1024)+"/"+ Math.floor (event.bytesTotal/1024) + "KB";
    }
    	
    function onComplete (e:Event):void{
    	formato.text = "archivo cargado con éxito";
    	audio.play();
    	removeChild(controlCarga);
    }
    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    June 7, 2021

    Hi.

     

    Thanks for the code.

     

    The problem is in the MP3 URL. You should use a direct link to your MP3 file. This Google Drive links actually redirects to the actual MP3 file.

     

    To get the progress bar working set its source property to the sound instance. Like this:

    import fl.controls.ProgressBar;
    
    var audio: Sound = new Sound();
    var controlCarga: ProgressBar = new ProgressBar();
    
    function onProgress(event: ProgressEvent): void
    {
    	formato.text = "Load..." + Math.floor(event.bytesLoaded / 1024) + "/" + Math.floor(event.bytesTotal / 1024) + "KB";
    }
    
    function onComplete(e: Event): void
    {
    	formato.text = "archivo cargado con éxito";
    	audio.play();
    	removeChild(controlCarga);
    }
    
    //audio.load(new URLRequest("https://drive.google.com/uc?id=10NdOk1E5gvyzbv98svIGo_bDY5Nea5ZZ&export=download"));
    audio.load(new URLRequest("YOUR_DIRECT_URL_TO_YOUR_MP3_FILE.mp3"));
    audio.addEventListener(Event.COMPLETE, onComplete);
    audio.addEventListener(ProgressEvent.PROGRESS, onProgress);
    
    controlCarga.source = audio;
    controlCarga.width = 320;
    controlCarga.move(50, 40);
    addChild(controlCarga);

     

    Regards,

    JC