A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: Buffering an external SWF with music

  1. #1
    Member
    Join Date
    Oct 2000
    Posts
    85

    Buffering an external SWF with music

    Can anyone point me in the direction of a way to buffer the audio in an external SWF so it streams instead of completely downloading to the browser before it starts playing? I have a preloader in the files, but the music won't start until it's completely downloaded, which makes the preloader (or buffer) useless.

  2. #2
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Is this swf just for music? Or is it an mp3 and a movie?

  3. #3
    Member
    Join Date
    Oct 2000
    Posts
    85
    Hey,

    It's an MP3 in a movie that I want to load into the main Movie. The mp3 is a full song...about 2 mb, so it needs to be buffered.

    Perhaps there is a way to load just the MP3s with buffering???

  4. #4
    only half-nerd PW.JaCkson's Avatar
    Join Date
    Dec 2000
    Location
    Treviso. Italy
    Posts
    139
    how about u load the mp3 externally with

    Code:
    song= new Sound();
    song.loadSound("song.mp3", true);
    the TRUE parameter means : "stream the sound". That way the mp3 will strat playing as it downloads.

    dunno if this is what u mean.

  5. #5
    Member
    Join Date
    Oct 2000
    Posts
    85
    By the way, in case I misunderstood you "iaskwhy". No, there is no video...just MP3 audio.

  6. #6
    Member
    Join Date
    Oct 2000
    Posts
    85
    Hey P.W. Yeah that's what I need to do. Can a preload bar be used with this somehow?

  7. #7
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    When you use loadSound, you don't need a preloader bar. The sound streams and starts after a 5 second buffer time, no matter how big it is.

    I was not particularly happy with how flash streams a sound using loadSound, so I came up with a different way to do it. A normal streaming sound would skip or hesitate if anything caused the processor or the loading to hesitate, which really made the sound sound terrible. So this is what I did.

    Make a new swf. Right away, make a new movie clip symbol. Import the mp3 to the library. Give the sound a linkage identifier of s. Check Export for ActionScript and "uncheck" Export in first frame. In this movie clip you just made, drag the sound to the stage, in the first frame of layer 1. Now you have to go way down the timeline and put a blank keyframe. For my sound of 1.7Meg, it was at like frame 7610. Keep going till you find the end of the blue jagged sound line. Stop there. Make a new layer for actions and put a stop at the end, none at frame 1. In frame 1 of the actions layer, add this line of code as a frame action:

    s = new Sound(this);

    This allows you to treat the sound as a streaming sound, but still have event sound type control over it once it is loaded in the main movie. Click the layer with the jagged line in it and set the Sync to Stream and 0 loops.

    Now, go back to the main timeline. Set the stage size to 10x10 pixels and drag the sound movie clip to the stage. Give it an instance name. I used snd4.

    In the main movie, after any preloader, or where you want this sound movie to start playing, add a frame action to load it to an empty movie clip off the stage somewhere:

    _root.mtClip.loadMovie("sond.swf");

    The movie will load, the sound will start to play in a few seconds and stream in. Unlike a streaming sound, you can start and stop this puppy by using the code to start and stop the movie clips timeline, like this:

    _root.mtClip.snd4.stop();

    Or:

    _root.mtClip.snd4.start();

    Works like a pause button and does not start from the beginning again. Whoa, wait, you want to set the volume? From the main movie timeline, just use:

    _root.mtClip.snd4.s.setVolume(20);

    Pretty neat? If you want to see it work, click my WWW link and listen to the intro. The headphones thingy is set up to pause the song. It could just as well be to set the volume, or I could have used both.

    Oh, by the way, that 1.7Mb sound file ended up being only a 375K swf. A nice little bonus.
    Last edited by iaskwhy; 05-27-2003 at 05:33 PM.

  8. #8
    Member
    Join Date
    Oct 2000
    Posts
    85
    Hey thanks! That looks very interesting. Thanks for the detailed explanation. I'm gonna try it out. One question, though...

    Does a volume "slider bar" work with this approach? I have one that I'm using right now with the attachSound method. Or will it only work with loadSound...or not?

  9. #9
    only half-nerd PW.JaCkson's Avatar
    Join Date
    Dec 2000
    Location
    Treviso. Italy
    Posts
    139
    that IS neat... nice job there...

    still i cant get the start() to work, just the stop() and setVolume(), but maybe im just doing something wrong... i cant chek out the thing at ur site cause it forwards me to the slide page automcatically (i hate that in a site)

  10. #10
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    I have a shared object cookie set up so you only see it once a day. To disable that, right click the movie when you get to the main site and click Settings, then check the Never box. It'll bypass the SO so you can see it as many times as you want.

    I think the volume slider could be made to work by targetting the s linkage identifier. There are so many different ways to do it, I'd have to see the code on the slider. But it could probably be made to work, as the setVolume thing works fine.

  11. #11
    Member
    Join Date
    Oct 2000
    Posts
    85
    This is the script on the main timeline for the volume slider.

    stop();
    sound1 = new Sound(this);
    sound1.attachSound("song");
    sound1.start(0, 0);

    The volume slide bar is in an MC named "vol".

    The script on the MCs timeline is this:

    volume = int(slider._x);
    sound1.setVolume(_level0.vol.volume);

    Sitting in this MC is a track graphic with another MC which is used for the slider. It's named "slider" and has a button in it for the dragging function.

    I can send the FLA if you want.
    Last edited by rockstar; 05-27-2003 at 06:47 PM.

  12. #12
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    This is in the sound movie? You don't need this anymore, cause your not attaching the sound:

    sound1 = new Sound(this);
    sound1.attachSound("song");
    sound1.start(0, 0);

    Try changing the code to:

    volume = int(slider._x);
    _root.mtClip.snd4.s.setVolume(_level0.vol.volume);

    Unless you used sound1 in that first frame instead of s. You'll have to adjust your path names to work for what you have though, it won't be the same as mine probably. You have to use the full path in the external swf so it can work from the main movie when it loads. Of course, it's hard to test. You have to have faith, cause it won't work when you test the sound swf, only when it loads to the main movie.

    If that doesn't work, send the fla using my contact mail link from my site.

  13. #13
    Member
    Join Date
    Oct 2000
    Posts
    85
    Actually that was the standalone version.

    The version that I was using to be loaded into the main movie, is set up with the same change that you suggested...doing this to Target the MC in the main movie that is loading this external SWF.

    So I guess what your saying, is that the volume slide bar will work the same way with your version of the streaming audio SWF as it does with the attachMovie method that I was previously using in my version (the one I sent you)?

    Many thanks for your help by the way.
    Last edited by rockstar; 05-27-2003 at 07:21 PM.

  14. #14
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    If you sent me something, I didn't get it.

    But, I was messing around with a volume controller I made awhile back, and it works fine. Check it out.

    http://www.flashbax.com/volumecontrolmcatach.html

  15. #15
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Ya, got your fla, it works fine.

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