I have an audio clip and a slider. The slider is acting as a progress bar (Timeline) for the audio clip. I can pause and play the audio also I can skip the track as well. Everything is working fine. The problem is slider isn’t moving smoothly it’s kinda jittery. Please edit it if somebody can. Thanks in advance.
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MusicPlayer : MonoBehaviour
{
AudioSource audioSource;
Slider slider;
public AudioClip track;
// Start is called before the first frame update
void Start()
{
audioSource = GetComponent<AudioSource>();
slider = GetComponent<Slider>();
audioSource.clip = track;
audioSource.Play();
slider.minValue = 0;
slider.maxValue = track.length;
}
// Update is called once per frame
void Update()
{
slider.value = audioSource.time;
}
public void MovePoition()
{
audioSource.time = slider.value;
}
public void play()
{
audioSource.Play();
}
public void pause()
{
audioSource.Pause();
}
}