- Home /
Audio Clip time
how can I store in a variable the length of an audio clip? thanks :D
Answer by voncarp · May 29, 2012 at 11:27 AM
Something like this:
using UnityEngine;
using System.Collections;
public class SoundLength : MonoBehaviour {
public AudioClip soundLoop;
private float soundLength; //the variable
void Start(){
audio.clip = soundLoop;
audio.Play ();
//the length of the sound
soundLength = soundLoop.length;
Debug.Log(soundLength);
}
}
Answer by corax · May 29, 2012 at 11:35 AM
Yes that's pretty smart, thanks :D but this code will actually plays the clip. I need the value to store it in a slider, I've a button to play the clip :D
I don't quite get the slider part.
The length of the AudioClip soundLoop is stored in soundLength based on:
soundLength = soundLoop.length
You can delete audio.Play() and audio.clip = soundLoop and still get the length of the AudioClip without it playing any sounds.
Your answer
Follow this Question
Related Questions
AudioClip scrub 1 Answer
Intro to looping music in single audio clip? 2 Answers
Read the pitch frequency of a audio clip 2 Answers
[iOS] Streaming audio with loop 1 Answer
How can I improve OGG music quality? 1 Answer