Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Frostbite23 · Apr 12, 2015 at 08:45 PM · audiopauseplaytroubleshooting

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 Audio.pause(); in my script, it pauses like it should but when i call Audio.play(); 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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Frostbite23 · Jun 04, 2015 at 03:43 AM

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.

 audiosource.play() //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 :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Matheuz · Apr 12, 2015 at 09:31 PM

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Audio keeps playing when paused 1 Answer

Music On/Off Switch 2 Answers

Listen to audio when stepping frame by frame in editor 1 Answer

Audio clip not playing 1 Answer

play audio on touch 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges