# Load mp3

**URL:** https://forum.kirupa.com/t/load-mp3/9611
**Category:** Uncategorized
**Created:** [December 15, 2002, 3:31am UTC](https://forum.kirupa.com/t/load-mp3/9611 "2002-12-15T03:31:41Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![brian\_monkey](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@brian\_monkey](https://forum.kirupa.com/u/brian_monkey)
#### Post date: [December 15, 2002, 3:31am UTC](https://forum.kirupa.com/t/load-mp3/9611/1 "2002-12-15T03:31:41Z")

</div>

is there any way I can dynamically load a mp3 and have a loading bar? or preloader?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 16, 2002, 3:09pm UTC](https://forum.kirupa.com/t/load-mp3/9611/2 "2002-12-16T15:09:40Z")

</div>

Yep. You preload MP3 exactly the same way you’d preload an swf.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 17, 2002, 3:39am UTC](https://forum.kirupa.com/t/load-mp3/9611/3 "2002-12-17T03:39:12Z")

</div>

can I have a preloader read the amount of the mp3 loaded if I just load the mp3 seperately and not through an swf. I am trying to load an mp3 by itself but I want to have a loading bar to display its progress.\<:}

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 17, 2002, 4:51pm UTC](https://forum.kirupa.com/t/load-mp3/9611/4 "2002-12-17T16:51:45Z")

</div>

Using the values from the getBytesTotal and getBytesLoaded method you can quickly create a sound buffer, so your sound won’t start playing until enough of the sound has loaded, much better method than waiting for your sound to preload.

```php
// create a holder for the sound, a instance of the sound object, and load in the sound file
    _root.createEmptyMovieClip("soundHolder", 1);
    userSound = new Sound(soundHolder);
    userSound.loadSound("mp3soundfile.mp3", true);
    
    // get the sound length
    soundLength = formatTime(userSound.duration)
    
    // set the textfields
    _root.min.text = soundLength.minutes;
    _root.seconds.text = soundLength.seconds;
    
    notDone == true;
    
    _root.onEnterFrame = function () {
    
        percentage = userSound.getBytesLoaded() / userSound.getBytesTotal() * 100;
        
        if (percentage > 5 && notDone == true) {
            notDone = false;
            userSound.start();
        }
        
        if (percentage >= 100) _root.onEnterFrame = undefined;
        
        percentageBar._xscale = percentage;
    
    }

function formatTime(milliseconds) {
    // find minutes expressed in decimal
    minutes = new Number((milliseconds/1000)/60);
    
    // split the minutes to find the minute (str[0]) and the seconds expressed in decimal
    str = new String(minutes.toString());
    str = str.split(".");
    
    // return an object with minutes and seconds properties
    // to find minutes, multiply the seconds expressed in decimal to find the seconds in integer format
    return {minutes:str[0], seconds: Math.round(("." + str[1])*60)};
}

```

h88 8]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 17, 2002, 5:06pm UTC](https://forum.kirupa.com/t/load-mp3/9611/5 "2002-12-17T17:06:28Z")

</div>

Hey h88. Nice piece of code. But are you sure it’s safe to overwrite loadSound (especially if you use loadSound inside the function)?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 17, 2002, 5:13pm UTC](https://forum.kirupa.com/t/load-mp3/9611/6 "2002-12-17T17:13:49Z")

</div>

Wow, how did’nt i notice that, i’ll edit the script now. :crazy:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 17, 2002, 6:58pm UTC](https://forum.kirupa.com/t/load-mp3/9611/7 "2002-12-17T18:58:15Z")

</div>

edited
