Checking if music is finished playing?

This forum is currently in read-only mode.
From the Asset Store
In this template the music plays without looping in your game
  • After way too much trouble playing music as OGGs through the sound effect system, I decided to bite the bullet and switch back to normal MP3s using the music system in XAudio2.

    However, my music is set up with an intro file that only plays once and then a looping portion. It appears that I will not be able to replicate this using the music commands, because there is no way to check if a piece of music (in this case the intro portion) has finished playing in order to play the next part. I can't even compare the length or change the playback position of a file because the music channel is separate from the sound effect channels. Is this just a missing feature or is there another way I am overlooking?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • With Mp3 i have actually no idea. With ogg you just can trigger the loop after the amount of time your intro is done...

    I would love it also if there is an good way to handle that problematic.

  • Yeah, looks like it is something that needs to be added. The problem with OGGs is that when you play the file (as a sound effect), it loads the whole thing into memory. This causes a momentary lag in the game as it does so, which would completely mess up any player.

    The solution to that was to cache the music files before the level loads, but it poses its own problem. Yes, I can load them in a "loading" layout beforehand, but there's no way to tell when it is finished! So I can set it to sit on a loading screen for an arbitrary amount of time, and if it's not finished then those files simply won't be cached and ready. If someone is playing off a slow disk or flash drive, this could be problematic. I was hoping to go back to the music playback in order to avoid all of this.

  • The solution to that was to cache the music files before the level loads, but it poses its own problem. Yes, I can load them in a "loading" layout beforehand, but there's no way to tell when it is finished!<font size="2">Well, there is a way to tell ;)

    Caching is done within one tick. There is no way to stop the process.

    + System: Start of layout

    -> XAudio2: Cache file AppPath & "music\first.ogg"

    -> XAudio2: Cache file AppPath & "music\second.ogg"

    -> System: Go to layout 2 with transition "None" lasting 0 MS

    This will switch to layout 2 as soon as the two files are cached. It will not go the specified layout before both files are fully loaded to memory.

    + System: TickCount Equal to 60

    -> XAudio2: Cache file AppPath & "music\first.ogg"

    -> XAudio2: Cache file AppPath & "music\second.ogg"

    + System: TickCount Equal to 61

    -> System: Go to layout 2 with transition "None" lasting 0 MS

    This will switch to layout 2 right after the files are cached, at tick 61.

    You could also start with doing all the loading of other stuff, then when you're ready to cache the ogg files, store the current tick count to a variable and go to another layout as soon as the caching is done:

    + System: Timer is Equal to 1000

    -> XAudio2: Cache file AppPath & "music\first.ogg"

    -> XAudio2: Cache file AppPath & "music\second.ogg"

    -> System: Set global variable 'cachingTick' to TickCount

    + System: Is global variable 'cachingTick' Greater than 0

    + System: TickCount Equal to global('cachingTick') + 1

    -> System: Go to layout 2 with transition "None" lasting 0 MS

    </font>

  • Mr. Ksoft,

    See if information in this post can help too. It has a link to an example play list by tulamide.

    scirra.com/forum/multiple-background-music_topic45271_post289487.html

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