A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [F8] Streaming MP3 issue

  1. #1
    Junior Member
    Join Date
    Nov 2006
    Posts
    4

    [F8] Streaming MP3 issue

    Hey guys. I am having a slight issue with MP3 streaming in flash. This is really my first flash project so bear with me if I'm doing something dumb

    My site is basically for my resume and music that I've done. I originally imported all my MP3's into flash and got everything working that way, and it was quite huge (~16 megs). I tried to find the easiest way I could stream my MP3's to get the size down, and the page is at www.gregoryhunt.com.. At 345k it's clearly a big improvement in load time.

    Everything seemed to work great, I was happy with it... And then I noticed that if I click play for one song, then on play again (for that song or another song) before it has started playing, it will start to overlap and get rather ugly. Also, seemingly at random, if I click one of the play buttons it will take quite a while to actually start playing. I can just put in some kind of "Please wait" text in there and take care of that problem, but if they don't wait and click another play button, it isn't good.

    Here is the simple play button code I'm using:
    Code:
    on(release){
    	stopAllSounds();
    s.loadSound("http://www.gregoryhunt.com/audio/dnb.mp3",true);
    }
    Each button uses a different s variable, ie s1, s2, s3, etc...

    What can I do to stop this from happening? I thought the stopAllSounds(); would take care of it, but it doesn't work if the sound hasn't actually started yet. I know in director you can just force everything to use the same sound channel, and thus not overlap, but I don't know a way to do it in flash.

    Thanks

    EDIT: I think what's happening with the "random" lag in playing an MP3 is, if you click one play button, then a second, no problem. If you don't wait too long and click a third, it will lag because it's still finishing loading the first 2 streaming files. Maybe there is a way to stop any other MP3's from loading once you click another button?
    Last edited by ghbass; 11-16-2006 at 07:12 PM.

  2. #2
    Senior Member
    Join Date
    Apr 2005
    Location
    FL, USA
    Posts
    442
    stopAllSounds() should actually work, but if you really want to avoid overlapping songs, just use one sound object instead of multiple ones. For a new song, load over the same object.
    Code:
    s = new Sound();
    button1.onRelease = function() {
    s.stop();
    s.loadSound("http://www.gregoryhunt.com/audio/dnb.mp3",true);
    }
    button2.onRelease = function() {
    s.stop();
    s.loadSound("http://www.gregoryhunt.com/audio/someOtherSong.mp3",true);
    }

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