Making a Timeline with Unity UI and FMOD

FMOD Version: 2.01.05
Unity Version: 2020.1.12f1

I’ve been experimenting with AR by making a simple audio app for Android. Without going into too much detail. The canvas becomes active when the music plays. This works fine and I have so far been able to get the music to Pause and UnPause with no problem, but I am having difficulty using the Slider UI component as a timeline jogger. What I have tried so far is creating a public function with a float parameter and then calling my instance with the setTimelinePosition method and using that in the OnValueChange Event Trigger attached to the Slider. It says this only takes an int as an argument which means I can’t use it as a dynamic float unless I convert the float to an int, which I have tried. Here’s the code I have created. I would appreciate any advice to be able to control the fmod timeline from within my unity game with the Slider. I may be way off with what I have done, but if someone knows how it’s done, please share.

using UnityEngine;
using UnityEngine.UI;
using FMOD.Studio;
using FMODUnity;

public class PlayPause : MonoBehaviour
    public EventInstance musicEvent;
    [EventRef] public string eventReference;
    public GameObject CanvasButtons;
    private PLAYBACK_STATE pb;
    public Slider timeline;

private void Start()
    timeline = GetComponent<Slider>();
    musicEvent = RuntimeManager.CreateInstance(eventReference); //Create the instance
    musicEvent.start(); **//event starts to play when the game object appears on the screen.** 

 //function is called when the slider's value is changed
  public void TimelineChange(int timLinePosition)

     //using the update function to determine when the music is playing, and if it is the canvas should 
      //be active. 
     public void Update()
        if (pb == PLAYBACK_STATE.PLAYING)

public  void OnClickPause()


public void OnClickPlay()




Studio::EventInstance::setTimelinePosition uses milliseconds in the form of an int, rather than a float. Depending on how you want to do it, you set the slider to use whole numbers and the max value to the length of the event (which you can get from Studio::EventDescription::getLength).

1 Like

I was unable to set the timeline even after I had used the getLength method. If you could give me an example of how you would implement it, I’d greatly appreciate it. The best result I was able to achieve was the track would start from the beginning after I changed the slider.

All the FMOD API functions will return an FMOD.RESULT that, if something isn’t working, you can check for more information on the issue.