Audio Pausing Trouble

Hello, I’m making an Audio media player right now and of course a series of unfortunate events occurred.

When i do
in my script, it pauses like it should but when i call;
it doesn’t seem to work, it plays the audio but it starts back from the beginning.
Ive looked up several posts saying how to resolve this but non seem to fit the situation I’m in right now.
However I’m thinking of when i pause the audio, it saves the time which it stopped, and when it plays it again, i want to go back to that time. How can i approach this the simplest way possible?

Try using yourSource.UnPause() instead of yourSource.Play().

most likely too late for this but i actually already solved this a long time ago. And by the way when I did use UnPause and Pause it didn’t work. So you have to create the pausing yourself. Which I did and it works.

For those of you wondering what I did is create a separate variable named captured time. (WARNING, PUDESO CODE)

var capturedtime : float;//this can be private, but we need a variable so we can save the time.

On the update function the captured time will equal the audio sources time.

capturedTime = audiosource.time //this should be in the update, and make it equal to audio time so its updating with the real audio time.

When you pause, just use the pause but before you pause, make captured time equal its self.

capturedtime = capturedtime; //it HAS to be written like this, cache the time first before pausing.
audiosource.pause() //then pause after, we cache it because if you pause or stop, the audio time will be set back to zero. So thats why you have to put captured time = captured time BEFORE pausing

Thats how you cache the time. When you hit play again, audio sources time should equal the captured time. //play the audio, it will start from zero but that will be fixed in the next line
audiosource.time = capturedtime //make the audio time equal to captured time, so we can play from where we left off

Now of course you can hate all you want and say that its not how you do it but hey, it works. There are other ways of doing this but i ended up doing this way without even thinking about it, I was looking for solutions and couldn’t find any. Until i made this. So for those of you who want to pause your audio, here is your solution :slight_smile: