- Home /
On iOS, how do I fade out music when the user presses the home button?
All the well-behaved games I've played on iOS fade out their audio when you push the home button. It's a cool effect, because it lasts until just after the home screen appears, making for a very smooth transition.
From what I have read, Application.Quit(), Application.CancelQuit() and MonoBehaviour.OnApplicationQuit() don't work/aren't called on iOS. This makes it difficult to detect when the user has pushed the home button. By default, my app's music is playing, so it continues to play until just after the home screen appears, and then it cuts off.
How do I make a Unity app handle quitting elegantly?
I had always assumed this was an automatic effect because it seemed ubiquitous among games. Perhaps it's working in this manner because you have the debugger running? Have you tried just running your app on the device without being in debug mode?
OnApplicationPause and OnApplicationFocus may be what you need, they're called when the iphone app gets paused or refocused
Answer by Dreamora 1 · Oct 15, 2010 at 06:37 AM
just dieing IS by apples definition quitting elegantly actually. you aren't meant to pull resources when the OS kills you.
Sure, but does Unity just die when the user hits the home button? $$anonymous$$usic keeps playing until a second or two after the home screen has fully appeared. I assume Unity isn't dying the moment the home button is pushed, but ins$$anonymous$$d letting the home screen appear and then dying?
Thats technically not even possible for Unity or any application to control. The application will get the request to shut down (-> willResignActive), then gets a bit of time and then is pushed into background or gets the kill notifier and then gets killed. it can only react to the notifications but not control them.
the reason the music plays on is the music playback of the iOS which lets the current chunk or whatever play to the end and fades its towards that end then. But the underlying application at that point has commonly stopped its execution. (background special tasks are an exception)
What are you talking about? I'm talking about reacting to the request to shut down by fading out audio, which sounds perfectly possible from the rest of your comment.
Your answer
Follow this Question
Related Questions
iPhone Home button 2 Answers
How can I swipe function that lets the player select buttons? 0 Answers
GUI.Button lags on iPhone 0 Answers