A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: music infinite loop?

Hybrid View

  1. #1
    Junior Member
    Join Date
    Jun 2000
    Posts
    9

    Cool

    how i can do a music infinite loop for background music?

  2. #2
    just set the loop to 9999 i think that should do the trick,
    i dont think theres an option for an infinite loop

    oioi

  3. #3
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,092
    you can also put the music in a movie clip

  4. #4
    Senior Moderator ®
    FK´s Banning Machine ™
    GMF ™'s Avatar
    Join Date
    Feb 2000
    Location
    Oslo, Norway
    Posts
    5,697
    it is 999

  5. #5
    Junior Member
    Join Date
    Jun 2000
    Posts
    9

    where?? & movie clip?

    where i put the 9999??
    in properties? sound? actions? or where? :P

    and.. for the movie clip
    how i do make the sound loop using a movie clip?

  6. #6
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,092
    click on Insert >>>

    New Symbol >>> Behavior: movie clip

    next add the music to keyframe1
    in the movie clip
    set the Sync to event
    set the loop to 99 times

    If you don't know how to set the loop and sync
    then i suggest you read the help files.

  7. #7
    Junior Member
    Join Date
    Jan 2007
    Posts
    4
    Sorry to resurrect an old thread, but this is the one that came up in my google search, so I thought it'd be good to post a solution so anyone else who's trying to find the answer will have it.

    Anyway, I came across this quick little trick that easily sets up an infinite loop without using any sort of 999 repeats (which can be problematic in long games or short loops, and just seems dangerous in general):

    music1.start();
    music1.onSoundComplete = function() {this.start();}

  8. #8
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    note that onSoundComplete does not guarantee a seemless loop.

    I believe that starting with Flash 8 you could specifiy "infinite" loop in sound properties for sounds on the timeline, though this does not help the problem with infinite loop in sound object.

  9. #9
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    i just tried this and it seems to work. it uses the sound object
    PHP Code:
    song = new Sound();
    song.loadSound("your.mp3"true);
    onEnterFrame = function () {
        
    pos song.position/1000;
        
    dur song.duration/1000;
        if (
    pos>=dur) {
            
    song.start();
        }
    }; 
    Last edited by EQFlash; 04-16-2008 at 10:40 AM.
    If you don't think you're going to like the answer, then don't ask the question.

  10. #10
    Junior Member
    Join Date
    May 2008
    Location
    Fort White, FL
    Posts
    1

    Flex 3.0 in AS3

    I just started flex a few days ago. I looked all over for a way how to loop background music. The only idea that I found worked was to put in the rediculously large # into the loop argument. Like so :

    MySound.play(0, 999);

    But I looked to the help files after still not satisfied~ In there I found SoundChannel. Used as so:

    var channel : SoundChannel = MySound.play(0, 0);

    You can catch the event when the song ends like so:

    channel.addEventListener(Event.SOUND_COMPLETE, PlayAgain);

    And here is how I handled that event:

    private function PlayAgain(event : Event) : void
    {
    channel.stop(); //<---- this I added just in case
    channel.removeEventListener(Event.SOUND_COMPLETE, PlayAgain);
    channel = MySound.play(0, 0);
    channel.addEventListener(Event.SOUND_COMPLETE, PlayAgain);
    }


    I had to declare the sound and the channel as members of the class for this to work due to scope and the inability to assign anything to the event.target. For some reason the sound will not loop if you just set the channel equal to the sound. It will play a second time but thats it! So I added another event listener to try an make it play again. Now I wasn't sure if the event listeners, if already set, stack in AS3. So as to not have thousands of the same event listener on this one channel I remove it just before reassigning the sound to the channel. I looped sounds past 6 times so i'm going to say this works well. I hope this helps.

  11. #11
    Junior Member
    Join Date
    Dec 2008
    Posts
    1
    I read from the AS3 Cookbook and the author said there is no way to make sound loop forever but there is a way to make sound plays for a very long time by using
    Code:
    this.play(0, int.MAX_VALUE);
    The sound will play for approximately 70 years!

  12. #12
    Registered User
    Join Date
    Aug 2012
    Posts
    1
    Quote Originally Posted by ookpalm View Post
    I read from the AS3 Cookbook and the author said there is no way to make sound loop forever but there is a way to make sound plays for a very long time by using
    Code:
    this.play(0, int.MAX_VALUE);
    The sound will play for approximately 70 years!

    thank you so much man, this code was EXACTLY what i was looking for! quick simple and easy way to loop some BG music or anything of the like, thanks again!

  13. #13
    Member
    Join Date
    Oct 2001
    Posts
    50
    Quote Originally Posted by ookpalm View Post
    I read from the AS3 Cookbook and the author said there is no way to make sound loop forever but there is a way to make sound plays for a very long time by using
    Code:
    this.play(0, int.MAX_VALUE);
    Can someone please tell me where to put this line of code in swish, i am totally newbie so please can you give me step by step instructions, I'll be grateful


    The sound will play for approximately 70 years!

  14. #14
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    If sound is external:
    PHP Code:
    var music:Sound = new Sound()
    music.load(new URLRequest("music.mp3")); 
    music.play(0int.MAX_VALUE); 
    // if music file is in another url (not in the same folder as the *.swf file) use "http://yoursite.com/music.mp3" instead.


    If sound is in library, with class name "music":
    PHP Code:
    var music1:music = new music();
    music1.play(0int.MAX_VALUE); 
    And i have a method to loop forever... you play it MAX_VALUE times, and add a listener to listen for the music to finishes, then play it it again MAX_VALUE times.

    PHP Code:
    var music1:music = new music();
    var 
    chan:SoundChannel = new SoundChannel();
    chan music1.play(0int.MAX_VALUE);
    chan.addEventListener(Event.SOUND_COMPLETEloop);
    function 
    loop(e:Event):void
    {
        
    chan music1.play(0int.MAX_VALUE);

    I have not waited for hours to see if it really loops, but I've waited quite long and it keeps playing...
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  15. #15
    the cheesy child bounceboy's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    323
    man that stinks so what i did was i made it start inside a movieclip and in the movieclip is 2 frames first one makes it start second stops it and when you press quit make it go to nextFrame(); for movieclip before it goes to another frame

  16. #16
    Junior Member
    Join Date
    Sep 2012
    Posts
    1
    I tried this, it worked. Thank you

  17. #17
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Sorry, the script is for flash as3. Swish doesn't support as3. Long time i don't use Swish so i can't help
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  18. #18

  19. #19
    Member
    Join Date
    Oct 2001
    Posts
    50
    Thanks a lot both of you.

  20. #20
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    So...with that tutorial Fruitbeard posted, you can do something like this to loop the music:

    PHP Code:
    onFrame (3) {
      
    mySound = new Sound();
      
    mySound.loadSound("song1.mp3");
      
    mySound.start(0999); 
    mySound.onSoundComplete = function () { 
    mySound.start(0999); 


    I've not tested it so i can't tell 100% it will work, but it should. Just replace "onFrame (3)" with the number of the frame of the scene you want the sound to start playing. It will keep playing throught all the frames until the last frame. If you don't use a stop(); on the last frame, the movie probably will repeat from its first frame, so the sound will start again over the already playing sound... so if you come up to this situation, i will read the swish tutorial to help you out.
    In as2, i would do something like:
    PHP Code:
    onFrame (3) {
    if(
    mySound.position != mySound.duration)
    {
    trace("it's playing");
    };
    else
    {
    trace("it's not playing");
      
    mySound = new Sound();
      
    mySound.loadSound("song1.mp3");
      
    mySound.start(0999); 
    mySound.onSoundComplete = function () { 
    mySound.start(0999); 
    }

    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

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