How do I make a playback queue?

0 favourites
  • 2 posts
  • I have 3 songs for soundtrack, in 3 audiofiles. What I want to do is, when the first finishes, the second plays, and when second finishes, 3rd plays.

    But can't find a way to do that. Anyone?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • In the event sheet, you can use Audio's "On ended" trigger.

    [quote:2fydp4u9]

    On ended

    Triggered when a sound with a given tag finishes playing. This is not triggered for looping sounds.

    On a naive level,

    When you play any sound, you can give it a tag. So you can create 3 "On ended" triggers for each audio tag. We will name each tag "musictag1", "musictag2" and "musictag3" for each 3 music respectively.

    When you play the first audio, give it tag "musictag1".

    When the first audio finishes, "On ended" trigger for "musictag1" will fire. In this trigger, you can play the second audio, and give it tag "musictag2".

    When the second audio finishes, "On ended" trigger for "musictag2" will fire. In this trigger, you can play the third audio, and give it tag "musictag3".

    When the third audio finishes, "On ended" trigger for "musictag3" will fire. In this trigger, if you wish to play the first audio again, you can just play the first audio and give it tag "musictag1".

    This naive implementation will have the music keep on playing these 3 musics forever.

    -----

    A possibly better approach:

    The problem with naive implementation above is that if you have 100 songs, doing all those "On ended" trigger charade for each audio is really silly and not feasible for bigger list of song.

    The following is one of the better ways to do this, which name all songs to be in sequential indices, uses variables to keep track of which music is being played and one "On Ended" trigger:

    1. Name all of your songs like this: "music1.ogg", "music2.ogg", ......., "music10.ogg" (Let's assume you have 10 music this time)

    2. Create a global variable named "totalMusic" that keeps track of how many music are there. Since we assume there are 10 music here, we will set the variable "totalMusic" to 10.

    3. Create a global variable named "currentMusic" which is used to track current music index.

    4. Now, play the first music "music1" and give it tag "musictag1", as well as set currentMusic to 1.

    5. Create "On Ended" Trigger which looks for the tag "musictag" & currentMusic. This means "On Ended" trigger will look for "musictag1", as currentMusic is set to 1 in step 4. In "On Ended" Trigger, do the following event and actions:

    -- add 1 to the variable currentMusic

    -- if currentMusic > totalMusic, set currentMusic to 1.

    -- play music "music" & currentMusic and give it tag "musictag" & currentMusic.

    With the logic in step 5 for "On Ended" trigger, this will play all of your 10 music one after another and also get back to the first music after the last music is finished.

    Do you follow this so far? If not, feel free to ask.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)