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)
{
musicEvent.setTimelinePosition(timLinePosition);
Debug.Log(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)
{
CanvasButtons.SetActive(true);
}
}
//pause
public void OnClickPause()
{
musicEvent.setPaused(true);
}
//unpause
public void OnClickPlay()
{
musicEvent.setPaused(false);
}
}