Checking if music is finished playing?

For questions about using Classic.

Post » Sun Jan 08, 2012 9:37 pm

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?Mr. Ksoft2012-01-08 21:39:04
B
8
S
3
G
5
Posts: 72
Reputation: 1,774

Post » Sun Jan 08, 2012 11:18 pm

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.
B
14
S
2
G
1
Posts: 28
Reputation: 1,152

Post » Sun Jan 08, 2012 11:37 pm

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.
B
8
S
3
G
5
Posts: 72
Reputation: 1,774

Post » Mon Jan 09, 2012 2:57 am

[QUOTE=Mr. Ksoft] 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![/QUOTE] 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
tulamide2012-01-09 02:59:38
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Jan 10, 2012 3:42 am

Mr. Ksoft,
See if information in this post can help too. It has a link to an example play list by tulamide.
http://www.scirra.com/forum/multiple-background-music_topic45271_post289487.html
B
5
S
1
G
1
Posts: 157
Reputation: 1,219


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests