PDA

Click to See Complete Forum and Search --> : music infinite loop?



fashion
06-29-2000, 02:08 PM
how i can do a music infinite loop for background music?

fluxxy
06-29-2000, 02:51 PM
just set the loop to 9999 i think that should do the trick,
i dont think theres an option for an infinite loop

oioi

jydnas
06-29-2000, 10:12 PM
you can also put the music in a movie clip

GMF
07-03-2000, 08:32 PM
it is 999 :)

fashion
07-04-2000, 03:09 PM
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?

jydnas
07-04-2000, 07:20 PM
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.

Phoenix00017
04-15-2008, 10:39 PM
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();}

hp3
04-16-2008, 09:13 AM
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.

EQFlash
04-16-2008, 10:35 AM
i just tried this and it seems to work. it uses the sound object

song = new Sound();
song.loadSound("your.mp3", true);
onEnterFrame = function () {
pos = song.position/1000;
dur = song.duration/1000;
if (pos>=dur) {
song.start();
}
};

Anruidoragon
05-26-2008, 12:00 AM
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.

ookpalm
12-12-2008, 11:32 AM
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

this.play(0, int.MAX_VALUE);

The sound will play for approximately 70 years!

bounceboy
03-04-2009, 04:44 AM
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

twilightwolf3
08-07-2012, 10:44 PM
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

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!

allenkerky
09-16-2012, 08:45 PM
I tried this, it worked. Thank you

star79
01-09-2014, 07:42 AM
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

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!

angelhdz
01-09-2014, 11:57 AM
If sound is external:


var music:Sound = new Sound()
music.load(new URLRequest("music.mp3"));
music.play(0, int.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":


var music1:music = new music();
music1.play(0, int.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.



var music1:music = new music();
var chan:SoundChannel = new SoundChannel();
chan = music1.play(0, int.MAX_VALUE);
chan.addEventListener(Event.SOUND_COMPLETE, loop);
function loop(e:Event):void
{
chan = music1.play(0, int.MAX_VALUE);
}


I have not waited for hours to see if it really loops, but I've waited quite long and it keeps playing...

star79
01-09-2014, 01:33 PM
If sound is external:


var music:Sound = new Sound()
music.load(new URLRequest("music.mp3"));
music.play(0, int.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]
var music1:music = new music();
music1.play(0, int.MAX_VALUE);
...

Thanks a lot for trying to help me, I appreciate it.
Can you please tell me where should I put the code? in which scene or frame? to be honest I never never used scripts in swish, so I totally lost
Also, the sound is in Library, but, I don't understand what does the word 'class' refers to
Note: um using swishmax 4
Note: my file has so many scenes and I want it to play across all scenes
Thanks again

angelhdz
01-11-2014, 02:13 PM
Sorry, the script is for flash as3. Swish doesn't support as3. Long time i don't use Swish so i can't help :(

fruitbeard
01-12-2014, 06:13 AM
Hi,

Perhaps here might help http://archives.swish-tutorials.com/tutorials.php?act=tut&id=102

star79
01-12-2014, 01:33 PM
Thanks a lot both of you.

angelhdz
01-12-2014, 01:46 PM
So...with that tutorial Fruitbeard posted, you can do something like this to loop the music:



onFrame (3) {
mySound = new Sound();
mySound.loadSound("song1.mp3");
mySound.start(0, 999);
mySound.onSoundComplete = function () {
mySound.start(0, 999);
}
}


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:


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(0, 999);
mySound.onSoundComplete = function () {
mySound.start(0, 999);
}
}

fruitbeard
01-12-2014, 02:05 PM
Hi,

The AS2 equivalent of "int.MAX_VALUE" is " Number.MAX_VALUE"