Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by Zib Redlektab · Nov 24, 2010 at 11:10 PM · audiopausemultitaskingunpause

Audio un-pauses when game gets focus

I've implemented a pausing system (in javascript) that uses AudioListener.pause = true in order to temporarily stop all sounds that are currently playing. This works fine for the most part, but I've found that when switching to a different application, and then returning to the game, the audio will resume playing, even if the game is still in its "paused" state.

I've managed to limit this for the most part by checking if the game should be paused at the beginning of Update, and using AudioListener.pause again, if it should be. However, you still hear a split-second burst of audio before it pauses. It's not really enough to be noticeable, but if you switch out and in enough times, the audio stops synching up with its subtitles.

Has anybody else encountered this, or have an idea for how I could be pausing better, so my AudioListener stays paused?

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

1 Reply

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

Answer by fireDude67 · Dec 01, 2010 at 04:44 AM

bool hasFocus = true;

void OnApplicationFocus() { hasFocus != hasFocus; if (!hasFocus) AudioListener.pause = true; // Or whatever you do to pause }

void Update() { if (GameIsPaused) AudioListener.pause = true; else if (AudioListnener.pause) AudioListener.pause = false; else return; }

JavaScript:

var hasFocus : bool = true;

function OnApplicationFocus() [ hasFocus = != hasFocus; if (!hasFocus) AudioListner.pause = true; // Or whatever you do to pause }

function Update() { if (GameIsPaused) AudioListner.pause = true; else if (AudioListner.pause) AudioListner.pause = false; else return; }

Let me know if you need a JavaScript version

Comment
Add comment · Show 2 · 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 Zib Redlektab · Dec 01, 2010 at 05:07 AM 0
Share

Thanks! Did not know about OnApplicationFocus at all! :D

avatar image rainyy · Mar 26, 2011 at 03:54 AM 0
Share

i need the JS version! Thanks :)

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

No one has followed this question yet.

Related Questions

How to know if Audio is Paused? 2 Answers

pause a audio inside game 1 Answer

How do I pause and unpause only some GameObjects at a time 1 Answer

Music On/Off Switch 2 Answers

why cant i play my scene? 2 Answers


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