# How do I get the "Position" of the Song between beats?

**URL:** <https://qa.fmod.com/t/how-do-i-get-the-position-of-the-song-between-beats/19602>\
**Category:** Unity\
**Tags:** unity, csharp\
**Created:** [December 1, 2022, 3:38pm UTC](https://qa.fmod.com/t/how-do-i-get-the-position-of-the-song-between-beats/19602 "2022-12-01T15:38:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LucaBGT](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@LucaBGT](https://qa.fmod.com/u/LucaBGT)\
**Post date:** [December 1, 2022, 3:38pm UTC](https://qa.fmod.com/t/how-do-i-get-the-position-of-the-song-between-beats/19602/1 "2022-12-01T15:38:43Z")

</div>

Hi everyone!

I’ve just started to use FMOD in Unity and, using the TIMELINE\_BEAT\_PROPERTIES, have created the base for a rhythm game, which starts events whenever a beat is hit thanks to FMOD communication with Unity. It currently works like a Metronome, so to say.

However, something I would want for this game is to find the position that the song is in at every given moment between each beat. The reason why I would want this is because I would like a slider to indicate the “position” between a cycle of 4 beats, similar to Parappa the Rapper where to player can see where they will place their inputs.

Any help on achieving this effect of a slider essentially moving with the song in realtime would be greatly appreciated, thanks!

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [December 5, 2022, 3:16am UTC](https://qa.fmod.com/t/how-do-i-get-the-position-of-the-song-between-beats/19602/2 "2022-12-05T03:16:41Z")

</div>

Hi,

There are a couple of things we will need:

1. The channel the sound is playing on [FMOD API | Channel](https://fmod.com/docs/2.02/api/core-api-channel.html).
2. The channel Group the channel belongs to [FMOD API | Channel Group](https://fmod.com/docs/2.02/api/core-api-channelgroup.html).
3. The sound that our song is playing from [FMOD API | Sound](https://fmod.com/docs/2.02/api/core-api-sound.html).

Before we do anything we will need to give the FMOD system a second to start up correctly so I would avoid calling any of these functions in the `Start()` function.

We use `FMODUnity.RuntimeManager.CoreSystem.getMasterChannelGroup(out FMOD.ChannelGroup masterCG)`, the [Master Channel Group](https://fmod.com/docs/2.02/api/core-api-system.html#system_getmasterchannelgroup) is where all sounds ultimately route to. From there, dig down using [getGroup()](https://fmod.com/docs/2.02/api/core-api-system.html#system_getmasterchannelgroup) till you find the channel group with the channel playing the sound. With the channel group, you can get the current channel using `currentChannelGroup.getChannel(out FMOD.Channel currentChannel)` which will contain our sound `currentChannel.getSound(out FMOD.Sound currentSound)`.

The sound will have the length of the song which we will use to assign the `maxValue` of the slider. `currentSound.getLength(out uint length, FMOD.TIMEUNIT.MS)`.

In the `Update()` loop once the sound has been retrieved you can use `currentSoundChannel.getPosition(out uint currentPlaybackPos, FMOD.TIMEUNIT.MS)` to assign the `slider.value` which will display the current position of the song every frame.

If you need any more assistance I am happy to provide more code snippets.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![jianinz](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jianinz/32/5807_2.png) [@jianinz](https://qa.fmod.com/u/jianinz)\
**Post date:** [November 20, 2023, 8:08am UTC](https://qa.fmod.com/t/how-do-i-get-the-position-of-the-song-between-beats/19602/3 "2023-11-20T08:08:00Z")

</div>

Hi,

Thank you for your explanation! I am currently facing the same issue where I would like to get the Position of current playback.

I took your suggestion and looked up this script example provided by FMOD [https://www.fmod.com/docs/2.02/unity/examples-dsp-capture.html](https://www.fmod.com/docs/2.02/unity/examples-dsp-capture.html). In the Update function, I have a script like following

```auto
        FMOD.ChannelGroup masterCG;
        if (FMODUnity.RuntimeManager.CoreSystem.getMasterChannelGroup(out masterCG) == FMOD.RESULT.OK)
            masterCG.getChannel(mChannels - 1, out currentSoundChannel);
            currentSoundChannel.getPosition(out currentPlaybackPos, FMOD.TIMEUNIT.MS);
            Debug.Log("Current playback ms : " + currentPlaybackPos);
        }

```

But what I could see from the Log is that currentPlaybackPos is always 0, the music gets played well in the game though which I assume that the sound should be successfully routed to the ChannelGroup. Could you provide any tips how to investigate further?

Thanks!

---

<div class="post-metadata">

**Author:** ![jianinz](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jianinz/32/5807_2.png) [@jianinz](https://qa.fmod.com/u/jianinz)\
**Post date:** [November 20, 2023, 10:23am UTC](https://qa.fmod.com/t/how-do-i-get-the-position-of-the-song-between-beats/19602/4 "2023-11-20T10:23:57Z")

</div>

I figured it out, using eventInstance API could achieve what I wanted. The simple line of code goes:  
` musicInstance.getTimelinePosition(out timelineInfo.position);`

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [November 20, 2023, 8:15pm UTC](https://qa.fmod.com/t/how-do-i-get-the-position-of-the-song-between-beats/19602/5 "2023-11-20T20:15:47Z")

</div>

Hi,

Thank you for sharing the solution!
