3
\$\begingroup\$

I spent some time playing with AudioSource.time & AudioSource.timeSamples and read some posts about them. So I get that due to audio compression I can't rely on .time for accuracy so I need to use .timeSamples. Yet, when I printed some output of how .timeSamples work coudn't understand the idea behind it at all. I simply made a 30 sec audio loop and with first play it starts from 7526 and 2nd time 38 and every next time it loops, starts and ends with different timeSample values. Why?

What I simply want to achieve is the thing I wrote in the header and also to be able to play the sound at for example the 5th or 10th or any second without losing the accuracy from the compression for android or ios. How can I do that?

\$\endgroup\$
1
\$\begingroup\$

Pausing and resuming playback can be achieved with this approach:

AudioSource audio = GetComponent<AudioSource>();
float playbackProgress = 0f;

//play
audio.Play();

//pause
playbackProgress = audio.timeSamples;
audio.Stop()

//resume
audio.timeSamples = playbackProgress 
audio.Play();
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.