# Get/Set playhead time within Programmer Instrument

**URL:** <https://qa.fmod.com/t/get-set-playhead-time-within-programmer-instrument/19000>\
**Category:** Unreal Engine\
**Tags:** blueprints, cpp, ue5\
**Created:** [July 14, 2022, 9:49am UTC](https://qa.fmod.com/t/get-set-playhead-time-within-programmer-instrument/19000 "2022-07-14T09:49:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SoundTek\_Studio](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/soundtek_studio/32/3395_2.png) [@SoundTek\_Studio](https://qa.fmod.com/u/SoundTek_Studio)\
**Post date:** [July 14, 2022, 9:49am UTC](https://qa.fmod.com/t/get-set-playhead-time-within-programmer-instrument/19000/1 "2022-07-14T09:49:17Z")

</div>

Like I formulated in the topic, my question is, if there is a way to get the time position of the playhead within a programmer instrument (not the Timeline of the Event!)?  
It gets even a bit more complicated: The programmer instrument, containing voice lines for dialogs, is running in async mode.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [July 18, 2022, 11:31pm UTC](https://qa.fmod.com/t/get-set-playhead-time-within-programmer-instrument/19000/2 "2022-07-18T23:31:13Z")

</div>

To get the playback position of any underlying sounds, rather than the Timeline position of the Event, you would need to drill down into the `EventInstance`’s `ChannelGroup` object using [`Studio.EventInstance.getChannelGroup`](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_getchannelgroup), iterate over it’s contained `Channel` objects with [`ChannelGroup.getNumChannels`](https://fmod.com/docs/2.02/api/core-api-channelgroup.html#channelgroup_getnumchannels) and [ChannelGroup.getChannel](https://fmod.com/docs/2.02/api/core-api-channelgroup.html#channelgroup_getchannel), and with each iteration call [`Channel.getPosition`](https://fmod.com/docs/2.02/api/core-api-channel.html#channel_getposition) to get the current playback position of each `Channel`.  
This should work the same with programmer sounds, but you will need to wait until the sound is started and the `Channel` is ready before doing anything.

---

<div class="post-metadata">

**Author:** ![SoundTek\_Studio](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/soundtek_studio/32/3395_2.png) [@SoundTek\_Studio](https://qa.fmod.com/u/SoundTek_Studio)\
**Post date:** [July 19, 2022, 9:30am UTC](https://qa.fmod.com/t/get-set-playhead-time-within-programmer-instrument/19000/3 "2022-07-19T09:30:01Z")

</div>

Cool, that seems to work.  
One more challenge: Is there a way to set the playhead within a programmer instrument?

I think the programmers try to construct a workflow for “scrubbing” audio in the Unreal-Engine Sequencer-Tool. (We know, by default scrubbing is not possible!)

---

<div class="post-metadata">

**Author:** ![SoundTek\_Studio](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/soundtek_studio/32/3395_2.png) [@SoundTek\_Studio](https://qa.fmod.com/u/SoundTek_Studio)\
**Post date:** [July 19, 2022, 11:44am UTC](https://qa.fmod.com/t/get-set-playhead-time-within-programmer-instrument/19000/4 "2022-07-19T11:44:52Z")

</div>

Oh and a follow-up question: Does that work with async sounds?

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [July 22, 2022, 12:10am UTC](https://qa.fmod.com/t/get-set-playhead-time-within-programmer-instrument/19000/5 "2022-07-22T00:10:23Z")

</div>

You can also call [`Channel.setPosition`](https://fmod.com/docs/2.02/api/core-api-channel.html#channel_setposition) on a playing channel and that should set the playback position.  
And yes it should still work with Async sounds.

---

<div class="post-metadata">

**Author:** ![SoundTek\_Studio](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/soundtek_studio/32/3395_2.png) [@SoundTek\_Studio](https://qa.fmod.com/u/SoundTek_Studio)\
**Post date:** [July 22, 2022, 1:00pm UTC](https://qa.fmod.com/t/get-set-playhead-time-within-programmer-instrument/19000/6 "2022-07-22T13:00:55Z")

</div>

We tried that, but it seems the audio file is always playing from the start position.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [July 29, 2022, 4:58am UTC](https://qa.fmod.com/t/get-set-playhead-time-within-programmer-instrument/19000/7 "2022-07-29T04:58:21Z")

</div>

It seems to be working fine for me. Here is a basic example of how to set the position of a playing programmer sound:

```cpp
if (programmerSoundInstance->isValid())
{
    FMOD::ChannelGroup *cg;
    if (programmerSoundInstance->getChannelGroup(&cg) == FMOD_OK)
    {
        int nGroups;
        cg->getNumGroups(&nGroups);
        int numChan;
        FMOD::ChannelGroup *subGroup;
        auto r = cg->getGroup(0, &subGroup);
        ERRCHECK(r);
        subGroup->getNumChannels(&numChan);
        if (numChan > 0)
        {
            FMOD::Channel *chan;
            subGroup->getChannel(0, &chan);
            chan->setPosition(1000, FMOD_TIMEUNIT_MS);
        }
    }
}

```
