I am making a Music Player app for Android in Unity3d. For show_currentPlayTime() function, I want to get AS.time value to show current playTime. For seek() function, I want to set AS.time value to get to that specific point of AudioClip. But, the problem is that AS.time is giving me 0.
I have tried setting AudioClip in AudioSource. It works that way, but the audio becomes distorted and shows abnormal behavior.
Variable Declaration:
public AudioSource AS;
[Range(0.0f, 1.0f)]
public Slider Volume;
public Slider slider;
bool isPlaying;
public List<AudioClip> AC = new List<AudioClip>();
int currentSong = 0;
Play Function:
public void Play()
{
AS.Stop();
AS.PlayOneShot(AC[currentSong]);
//AS.clip = AC[currentSong]; ---
//AS.Play(); ---
//AS.clip = AC[currentSong]; ---
//AS.PlayOneShot(AS.clip); ---
clipInfo.text = AC[currentSong].name;
Debug.Log(AC[currentSong].name);
CancelInvoke();
Invoke("Next", AC[currentSong].length);
isPlaying = true;
}
The program runs with using --- lines, in above code, but with that, the audio becomes distorted.
Music Seek function:
public void MusicSlider()
{
AS.time = AC[currentSong].length * slider.value;
slider.value = AS.time / AC[currentSong].length;
Debug.Log(AS.time);
}
AS.time gives me value = 0.
AudioListener? Is it on the same GameObject as theAudioSource? - Ruzihmpublic void Play() { AS.Stop(); AS.clip = AC[currentSong]; AS.Play(); clipInfo.text = AC[currentSong].name; ...? - Ruzihm