- Home /
AudioClip scrub
I'm trying to create an audio player with scrubbing functionality. I was able to load, play and pause the clip, as well as to create a slider that move accordingly to the length of the clip (the more the time passes, the more the value of the slider is. . .). Now I have to implement the possibility to "scrub" the audio clip, so you can move the slider and play a specific section of the clip. I was trying something like:
slider1.value = scrubTime;
audio.Play(scrubTime);
but that doesn't work. Is there a way to play a specific part of the clip?
Answer by crtapps · Jun 01, 2012 at 07:34 AM
Delay allows a source to be played later at a specific sample-accurate point in time. Note that the delay must be set according to the reference output rate of 44.1 Khz, meaning that Play(44100) will delay the playing by exactly 1 sec. Note: To obtain sample accuracy with an AudioClip with a different samplerate (than 44.1 khz) you have to do the math yourselves. Delaying an audiosource with an attached AudioClip with samplerate of, say, 32 khz, with 16k samples(.5 sec) is done by Play(22050). ((44100/32000) * 16000 = 22050).
here is the ref:
http://unity3d.com/support/documentation/ScriptReference/AudioSource.Play.html
Yes so I must first of all store in variables my khz & samples and then do the math...It's pretty boring because I have different tracks with differente data. $$anonymous$$aybe I can use getoutputdata. . .
Perhaps the simplest way is to get the all the audio using the same sampling rate.
Your answer
Follow this Question
Related Questions
Array of AudioClips not playing, please help 3 Answers
Audio not importing correctly? 2 Answers
How exactly does AudioClip.Create() work? 3 Answers
Audio not working properly after scene change 0 Answers
Audio OneShot not playing! 1 Answer