6 Replies Latest reply on Jun 21, 2007 10:44 PM by Optikalefx

    Looping Sound

    TRI0N
      Recently I submitted a post in regards to help on an issue that I'm experiencing with looping a streaming mp3 file to where I want the music to loop over and over after its reaches the end of its song.

      I was too quick to check off "This Post Answers My Problem" and well here I am again with the same problem.

      My file:
      2 layers - 1 Action Script, 2 Music Controls

      My action script:
      var tune:Sound = new Sound();
      tune.loadSound("breathe2.mp3", true);
      tune.start(0,50);

      play_mc.onPress = function() {
      tune.stop();
      tune.start(0,50);
      }

      stop_mc.onPress = function() {
      tune.stop();
      }

      Now what I was lead to believe is that the "tune.start(0,50);" would do is loop (repeat) this song 50 times before it actually stopped playing. However this does not. It plays once and stops.

      Any help would be great!
        • 1. Re: Looping Sound
          Optikalefx
          I know there is an actionscript way to do this, but this will work.

          make a movieclip and attach your mp3 to the frames. and drag the frames out until the blue stream is over. and note what frame it ends on.

          when you play ur music, just have that movieclip play, and have an if statement that gets the current frame of the music movie clip and says if its at the end, play back at frame 1

          if (music_mc._currentframe == 100) {
          music_mc.gotoAndPlay(1);
          }
          //saying your music_mc has 100 frames of music.
          • 2. Re: Looping Sound
            TRI0N Level 1
            However this isn't the ideal way I want to present the music. The music must stream rather then Pre-Load the whole filesize before it begins to play. The idea is not to have the users wait for the music to load. So it streams what is need to play then continues to play the music as it continues to download the rest of the song. This is a full size stero mp3 music file we are presenting at enviormental sound. So having it load quickly to play as the rest of the site is ready to browse is a major important factor.

            Thanks for the suggestion never the less.
            • 3. Re: Looping Sound
              Optikalefx Level 1
              ok i got off my lazy *** and found this...still a little lazy, i didnt test it

              // Sound Object
              myLoop = new Sound();
              myLoop.attachSound("myLoop01");
              myLoop.start(0,0);
              myLoop.onSoundComplete = function() {
              myLoop.start(.1, 0);
              };
              • 4. Re: Looping Sound
                TRI0N Level 1
                Okay I'm going to assume that the .1 in (.1.0) is an error and should be (1,0)?

                Also I'm going to guess this Action Script below will fix my problem? I sure hope so...

                var tune:Sound = new Sound() ;
                tune.loadSound("breathe2.mp3", true) ;
                tune.start(0,0) ;
                tune.onSoundComplete = function() {
                tune.start(1, 0) ;
                }

                play_mc.onPress = function() {
                tune.stop() ;
                tune.start(0,0) ;
                tune.onSoundComplete = function() {
                tune.start(1, 0) ;
                }

                }

                stop_mc.onPress = function() {
                tune.stop() ;
                }


                Before I go off making any wacky changes lets discuss this further and make sure its an effective way to do this. Again thanks for your input and any further input you may provide. Any help is better then no help.
                • 5. Re: Looping Sound
                  kglad Adobe Community Professional & MVP
                  if you're streaming your sound, the sound instance's start() method is ignored.

                  just use the onSoundComplete method to start() your sound when it finishes.

                  p.s. i don't think you want to offset your start by 1 second (or .1 second), so you shouldn't use any parameters in the start() method.
                  • 6. Re: Looping Sound
                    Optikalefx Level 1
                    kglad the only reason the .1 was there is because when it stars again after the first is complete, it pauses, and for a constant loop of sound it wont pause if it can start 1 milisecond in, idk why it does that.