Problems with audio seeking and playback time

Discussion and feedback on Construct 2

Post » Sat Aug 09, 2014 9:24 pm

My apologies if this is not the appropriate forum...I dont know if this may be a bug (probably not?) and I actually know how to do this, but I cant get it working right...

Ok, first, what Im trying to do:

Im making a racing game, and I want that every time you complete a lap, the music changes to another version of the same tune with more instruments.

Since all the music (small loops) have the same duration, logically I want that when I play a new track it begins at the same point the last one was on to make it seamless.

To put an example, think of Super Mario World when you get on Yoshi and some bongo-like drums get added to the music (here)

The problem? It kinda works....sometimes. I cant get this to work consistently and the new music usually just starts from the beginning.

What Im doing is using audio seek on the new track with the playbacktime of the previous one.

First thing that comes to mind is that since playbacktime accounts for total playback time (it doesnt loop with the sound) maybe the new sound doesnt like that you try go to a time point beyond the duration of the sound file....but this also fails (sometimes!) if you try to go to the next track before the first loop is complete. And even is the sound has already looped, it sometimes works as intended anyways....

Anyways, I also tried to use the music without looping and loop it manually with the "On ended" audio condition, but it doesnt fix this.

I made a very simple capx to illustrate it, it has 3 tracks:

-A 5 to "Go!" countdown (So whe can cleary know at wich point of track we are)
-Same track as the previous one with some drum beat.
-Same track as the previous one with another extra drum.

And 2 buttons to select track. Fiddle around with the buttons for a while and you will see how it sometimes works for a while, then stops working properly, then start to work right again, etc...

CAPX

...yeah, I know, I could just have the extra instruments alone in separate tracks, play everything at the same time, and mute/unmute the "layers" as needed...but since what Im trying to do makes sense to me I want to know why this doesnt work :roll:
B
26
S
7
G
1
Posts: 74
Reputation: 2,092

Post » Sat Aug 09, 2014 11:24 pm

Looks like a fun tinkering of sound. Have you tried using the files as Sound rather than music. Importing as music flags them to be audio streamed. So only preload a little audio ahead of time and forget prior. Sound files just load into memory.

My suggestion would be preload all the tracks. And then manually track the time and try that way. Let us know how it goes :)
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,038

Post » Mon Aug 11, 2014 12:51 pm

Pretty good advice!

I prescinded of playbacktime and made a variable to keep time (just adding dt every tick), with the music on not looping mode. Then with the on audio ended condition I manually loop the music and at the same time set this custom timer to 0.

Works perfectly if I put the files on the sounds folder, not so good on music for some reason, but still far better than before.

Using the music folder it apparently fails if I change the track before it loops (wich....since its not even a "real" loop makes no sense, actually :lol: ) after the first loop it works consistently. Since in my game its impossible to complete a lap before the music loops, I guess I'll use the music folder...

Since im targeting mobile (preload wont be an issue there) it will help to save RAM...

Thank you! :D
B
26
S
7
G
1
Posts: 74
Reputation: 2,092

Post » Mon Aug 11, 2014 6:32 pm

Have you tested on mobile? When you place all the music in the sounds folder, don't you get insanely large loading times?
B
8
S
1
Posts: 53
Reputation: 787

Post » Mon Aug 11, 2014 7:28 pm

No, I didnt, because I'll use the music folder on mobile...In any case, the music im using for this little trick are 3 short loops of like 12 seconds, I guess It would not take that long to load anyways if that was the case.

I may have to preload the tracks, though...I know preloading (lag) is not an issue on a mobile app but it isnt an issue either in preview....but preloading the music definitely fixes the issue I was having for some weird reason.

Question:

It makes sense to put music in the music folder if Im going to preload it anyways? Do I lose the advantages of using the music folder? (Saving RAM)

As I said, since the files I need for this are not so heavy, I wouldnt mind putting them in "sounds" and have a little longer loading time. But if using "music" I can save RAM I prefer that. Does preloading negate that effect?
B
26
S
7
G
1
Posts: 74
Reputation: 2,092


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 9 guests