3 Replies Latest reply on Feb 27, 2007 10:32 AM by cmsnell

    preloading MP3 audio

    miquael Level 1
      i'm trying to preload an MP3 file by about 20% before playing. this should be somewhat simple to do ...

      i've got a bar loader going, and everything works. but the sound actually does not play until 100%. why?

      _root.preload = 20;

      - - -

      var my_sound2 = new Sound();

      my_sound2.onLoad = function(success) {
      if (success) {
      // my_sound2.start();
      loader_intro._visible = false;
      loader_intro.bar_mc._xscale = 1;
      status_txt.text = "Sound loaded";
      } else {
      status_txt.text = "Sound failed";
      }
      }

      my_sound2.loadSound("content/audio/0/MO2.mp3", false);
      loader_intro._visible = true;
      loader_intro.bar_mc._xscale = 1;

      my_sound2.onSoundComplete = function() {
      my_sound2.stop();
      my_sound2 = clear;
      fade();
      }

      // audio loader
      loader_intro.onEnterFrame = function() {
      var pctLoaded:Number = Math.floor(my_sound2.getBytesLoaded() / my_sound2.getBytesTotal() * 100);
      if (!isNaN(pctLoaded)) {
      loader_intro.bar_mc._xscale = pctLoaded;
      //loader_intro.label_txt.text = pctLoaded + "% loaded";
      if (pctLoaded >= _root.preload) {
      trace ("pl: " + _root.preload);
      my_sound2.start();
      }
      if (pctLoaded >= 100) {
      loader_intro.onEnterFrame = undefined;
      }
      }
      };