Problems with audio seeking and playback time

0 favourites
  • 5 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • 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 (

    Subscribe to Construct videos now

    )

    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

  • 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

  • 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 ) 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!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Have you tested on mobile? When you place all the music in the sounds folder, don't you get insanely large loading times?

  • 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?

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