Load Music via Programmer Instrument and Scrub / Set Timeline Position

Hi there,

Currently I have a setup in Unity that allows user to play music and able to scrub/seek position like a music player. That works fine for music event with music track already in them.

What I would like to do is allow player to load music file from their PC.

I have looked into Programmer Instrument and followed the example https://www.fmod.com/docs/2.02/unity/examples-programmer-sounds.html

In Fmod, I made a new event, added Programmer Instrument track and set it to async.

I am able to load music file from SreamingAssets folder and play it. However,

The problem I am facing in unity is that I don’t seem to be able to use set timeline position on this event to scrub/seek. However I am able to pause/unpause it.

Any guidance is appreciated.

Setting an instrument to async means that once triggered by the timeline, it will play back from start to finish independent of the timeline position. If you want to seek a time or scrub through the programmer instrument using Studio::EventInstance::getTimelinePosition, then the programmer instrument will need to be synchronous.

Thanks for the reply Louis!

According to my understanding, I set it to async is to allow for programmer instrument to accommodate to different music length.

Is there any way around this?

Thanks!

The simplest way around this would be to ensure the Programmer Instrument is synchronous and set to an arbitrarily long length such that it will accommodate most foreseeable user inputs. Otherwise, since Studio events are designed in such a way that the timeline controls seek functionality, it becomes a hassle to accomplish what you want, as you need to get the Programmer Instrument’s underlying Sound, then find the Channel that the Sound is playing on (this is the hard part), and set the Channel’s position.

As such, you may find it more useful to bypass the middleman, so to speak, and directly use the Core API to load and play your user’s audio file instead of a Programmer Instrument. If you’ve set up specific effects on a bus in Studio that your existing event is using, you can retrieve that Bus’ underlying ChannelGroup with Studio::Bus::getChannelGroup and play the Core API Sound on that ChannelGroup.

That said, the ability to seek asynchronous instruments with setTimelinePosition() would be useful, so I’ve added it to our internal feature/improvement tracker.

Thanks for your detailed explanation.

I ended up using the first method ( getting channel and set the channel position )