Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 Mrten · Nov 24, 2011 at 10:44 AM · androidaudioruninbackground

Audio playing at inappropriate times on Android due to OnApplicationPause

I've been experiencing problems with audio playing at inappropriate times on Android, like when the App is not in focus or on the unlock screen of the phone. It seems that eventhough I've got Run In Background unchecked the game is in fact on at times in the background. The easiest way to reproduce it is by quickly turning the phone's screen on and off while the game is running. This gets the phone to its unlock screen but with the sound of my game playing in the background. A logging of OnApplicationPause and OnApplicationFocus tells me that the game indeed is unpaused in the background.

Am I missing something or is this be a Unity bug? As it is now it leaves me to make some sort of global muting system, which feels like a weird solution to something that should be handled by the Unity player the problem is unmuting since I cannot listen to OnApplicationPause(true) as this obviously is triggered at the wrong time.

Comment
Add comment · Show 3
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 Keryu · Dec 01, 2011 at 08:36 PM 0
Share

I had a very similar issue on an Android tablet. I could never get OnApplicationFocus() to trigger; anytime I lost focus on the app, my logs always showed OnApplicationPaused() was being triggered.

For OnApplicationPaused(), are you checking if the boolean parameter is true before running code to pause the audio? If so, try running your code to pause the audio regardless of the parameter's state. $$anonymous$$y issue was that the audio seemed to be correctly pausing as the game first lost focus, but when I resumed the app, the audio began playing again. Once I called for my audio to pause regardless of whether OnApplicationPaused() was showing true or false, the audio correctly paused.

I'm only able to test on a $$anonymous$$indle Fire at the moment, and haven't seen OnApplicationFocus() trigger yet. Which device are you testing on?

avatar image Mrten · Dec 02, 2011 at 08:02 AM 0
Share

I'm on a Nexus S and the same thing happens to me, no OnApplicationFocus, only OnApplicationPause.

Your suggestion with not listening to the parameter is interesting, but how would you know when to unmute it, when you actually DO want to unmute it?

avatar image Keryu · Dec 02, 2011 at 08:11 PM 0
Share

@$$anonymous$$rten, when OnApplicationPause calls, I bring up a pause menu and mute my background audio track. Then, once I click the 'resume' button, I turn my audio back on.

Is it mostly just background music you're having the issue with? If so, you can try muting it when OnApplicationPause triggers (regardless of the boolean state) and then be sure to turn it back on once you click resume (or however you allow your game to continue after being paused). If you have a more complicated setup and you're trying to mute/unmute specific audio tracks, I'm not entirely sure this solution will work cleanly for you.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kromenak · Dec 03, 2011 at 12:57 AM

This should have been fixed in the latest Unity release - at least, it was fixed for us. See http://unity3d.com/unity/whats-new/unity-3.4.2

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Sound Cracks or Lags on ZTE Blade? 0 Answers

OnAudioFilterRead issues on Android? 1 Answer

Mute toggle nor working on Android?? 0 Answers

Audio stuttering on Android when timescale == 1, but not when 0.01 0 Answers

AudioMixer works in editor but doesn't work in Android Device 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