- Home /
Proper background music looping
It's pretty easy to make an audio clip loop so that when it ends, it loops back to the beginning. How can I make it instead loop back to a specific loop point? Can some audio file types have the loop points incorporated or will I have to do it all within Unity?
If it's a last resort I could separate out the "intros" for the tracks and just start the looping portion when that's done. Is that seriously the easiest way? Is there a function that calls when an audio clip ends?
Answer by mattyman174 · Feb 17, 2014 at 12:52 AM
Im not well versed in AudioClip Manipulation but you will have to build a new Audio Clip with your specific section you want Looped and then play that back to the User.
http://docs.unity3d.com/Documentation/ScriptReference/AudioClip.html
Use that class to take Audio from a File and then get the samples you want looped and then rebuild a new audio clip to play as the loop.
Thats the basic theory i understand about it.
Hope it helps.
Answer by xt-xylophone · Feb 17, 2014 at 12:45 AM
Check out AudioSource documentation. I believe what you want is possible.
You could check if it has stopped by checking the isPlaying bool. If between frames it went from true to false, it has ended. Make sure loop is off though or you won't know. In fact if you know it should be playing all the time, if its false you will know.
Answer by 5argon · Jan 08, 2016 at 01:06 PM
@Warlyte This Introloop plugin will do exactly what you want : http://forum.unity3d.com/threads/378370/ You can give each audio 2 boundary points and it will loop to the first when it reaches the second.