Forum rules - please read before posting.

Queueing loopable music tracks

edited March 18 in Technical Q&A

I have a loopable music track playing and I queue another loopable music track.

I have noticed that when the first loopable music track is added, the logic queues another instance of that first music track, but then when I queue the second music track it’s added after the first queued one (at the tail of the queue).

Is there a way to clear the queue and add the second loopable music track (without touching the source code)?

Comments

  • On top of that, I have noticed that even if the first loopable music track finishes, the logic never fetches the first track of the queuedSoundtrackarray and it keeps playing the first loopable music track over and over. Am I doing something wrong here or did I hit a bug? I am using version 1.85.5 in Unity 6.2

  • Here's how I play the first loopable track:

    and here's how I queue the second loopable track:

  • edited March 18

    Update I think I have found the culprit here: The Transition time (s) (aka fadeTime internally) of my actions is 0, meaning that in the Soundtrack.cs in ~ line 120, the if (nextSoundtrack.fadeTime > 0f) is never satisfied, and there's no else statement there to handle this case.

    Here's how I fixed it: Given that in this case the nextSoundtrack.fadeTime is actually 0 we can just set audioSource.loop = false; in the else statement so that the logic will hit the if (!IsPlaying ()) statement of line 100 once the currently running soundtrack finishes playing and the next (queued) soundtrack will be picked up.

    I have tested the above change and it works in my case but maybe it introduces regressions.

  • Are you adding both tracks to the queue at the same time? I'm not clear on the underlying situation.

    Track-queueing isn't really intended for looping tracks - since the queuing occurs automatically when the track at the front of the queue ends.

    If you want to play a new looping track, have you tried the Crossfade option?

  • No, I am not adding both tracks to the queue at the same time.

    I am playing the first track with looping enabled when the scene starts and then at later point, after a player's action, I am queueing the second tracking with looping enabled.

    I don't want to crossfade them, cause they are two versions of the same theme so what I essentially want is when the first track finishes playing, the second track that's already queued to begin playing and loop, so that the transition will be seamless.

  • I think what you'd want to do in this case, then, is prevent looping from a custom script or Action with:

    KickStarter.stateHandler.GetMusicEngine ().audioSource.loop = false;
    

    The change you've made to the Soundtrack script will have unintended side-effects.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.