A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Preloading - or at least caching - external mp3s

  1. #1
    Junior Member
    Join Date
    Feb 2001
    Posts
    19

    Preloading - or at least caching - external mp3s

    Help! I've been searching and reading for awhile, and i'm still a bit unsure about the easiest/best way to do this. Basically, I've got 5 external mp3s that i'm using as a soundtrack, starting with the first loop then I'm randomly calling them once each instance has finished playing. All of that's working great:

    var music:Sound = new Sound();
    music.loadSound("loop1.mp3", true);
    music.onSoundComplete = function() {
    filename = ["loop1.mp3", "loop2.mp3", "loop3.mp3", "loop4.mp3", "loop5.mp3"];
    i = filename.length;
    k = Math.floor(Math.random()*i);
    music.loadSound(filename[k], true);
    _root.reader.text = filename[k];
    }

    The problem is, I can't figure out how to get loop2 - 5.mp3 stored in the cache prior to them getting called by the script. Even though they're streaming, there is a small pause the first time they're called.

    Help?

  2. #2
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    There are two ways you could try this.

    #1 Instead of using onSoundComplete to load, use the onload event to start loading next sound in an alternate sound object. As the first sound finishes playing the second will already be loading, and hopefully if the user has enough bandwidth, will finish buffering before the first sound is finished playing, creating a kind of seamless playback. A sound object can only contain one mp3 at a time. The trick is to load in alternate sound objects so as to not overwrite the currently playing mp3. Once the mp3 starts to load you can stop it so that it does not automatically start playing which could overlap the previous mp3. Use onSoundComplete() to call the start() method to play sounds in sequence.

    #2 load all the sounds up front then play them in sequence.
    Flash executes the onload event when a sound completely loads. Use the load event to load the next sound, repeat until you have loaded all sounds. Increment a counter each time a new sound loads. Once you have loaded all sounds, counter is same as array.length - 1, then you know all sounds loaded go ahead and start sound sequence.

  3. #3
    Junior Member
    Join Date
    Feb 2001
    Posts
    19
    I'm a little confused - could you possible provide basic code examples of those two methods? I had assumed that when you use streaming you couldn't use the start method... are you suggesting I load them all as event sounds?

  4. #4
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    you can use start() with streamed mp3, as long as your users have player version 6r40 or greater.

    suggestion #1 pertains to playing a sequence of streamed mp3
    suggestion #2 pertains to loading, not streaming, your mp3 upfront then playing them in sequence from the onSoundComplete event.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center