How to Set Timeline Position via Slider?

Hi,

I have a music (4 minutes) that I want to add a slider that changes the timeline playback position.

I could get the timeline position and make the slider move accordingly, but I calculated the milliseconds by hand.

[SerializeField]
private Slider lengthSlider;

private void Update()
{
    myTimelinePosition();
}

public void myTimelinePosition()
{
    EventInstance.getTimelinePosition(out int position);

    lengthSlider.value = position;
}

I have 2 questions:

  1. Is it possible to get the length of a timeline or a region automatically?

  2. Is it possible to change via slider in Unity the positioning of the play head and continue the music from that new position? Like we do when watching a video in youtube. We see the progress bar and click on the bar to move to a different part of the video/music.

Thanks!!!

  1. To get the length of the timeline get the EventDescription from the EventInstance with Studio::EventInstance::getDescription, then you can call Studio::EventDescription::getLength.

  2. Have you tried using Studio::EventInstance::setTimelinePosition? You can set your instance to a new position using that.