Can applicationWillResignActive be used for pausing the application - iphone

In the MainViewController, I have a play/pause button. I was having problem in coding for the pause function because when i was using audio player pause it was pausing only the audio player but in background my application was still executing. I have used NSTimer for displaying various UIViewControllers. While audio player is paused it is still displaying UIViewControllers because of NSTimer.Whereas i wanted complete pause audio player & application execution as well at the same time.
I found this -applicationwillresignactive. Do you think this -applicationwillresignactive can help me when i want complete pause audio player plus application pause.
Please suggest.

applicationWillResignActive and applicationDidEnterBackground are called when home button is pressed.

Related

How to state commands of 'animation stop animating'?

I have an app I'm creating and I need some help. Under the view did load I have a code to play music which is fine. Then there is button saying 'play' when they click play the music STOPS and a animation starts. Now after the animation finished 2 buttons appear. How would I state animation stop animating like a void or ibaction so then I can put when the animation stop animating happens play the music again. If this dosent make sense please feel free to ask questions, Im a beginner so take it easy on me :) thanks
+ (void)animateWithDuration:(NSTimeInterval)duration
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
Would allow you to know when an animation is completed, code in the completion block will be executed when the animation finishes.

iPhone - Need to replay background sound when it comes to foreground from background

My application plays a background music when it launches. It stops when I quit the application. But not playing the music again when I open my application. The application has 2 views and I want to play background sound on only main view. So when the app launches it should play the sound until user quit the app or when the user goes to the second view in the app. The sound should be played again only when the user returns to the main view. Currently, I am calling the sub function which plays the sound in 'viewDidLoad' function. please help.
Thanks
Try using this method in your AppDelegate:
- (void)applicationDidBecomeActive:(UIApplication *)application
DidBecomeActive Apple Documentation

Issue with MPMoviePlayerController playing an audio after a YouTube Video is opened in a Webview

In one View Controller ViewController1, I have tried to open a You tube video embedded in a UIWebview. It opens in the Movie Player window and then I use the "Done" button to come out of the movie player window. Again in another view controller ViewController2 in the same application, I open a MPMoviePlayerController(MPMoviePlayerController *audioplayer) to play an audio file using streaming. However, it remains in the paused state on opening the player. Even when i call the method [audioplayer play], the application automatically sets back the playback state to paused (i rechecked and it is not done through my code).
But if i reopen the application and in view controller ViewController2 i play the audio alone, then MPMoviePlayerController *audioplayer plays successfully.
Any idea what i might be doing wrong ?
This issue was found to be specific only to ios4.0.
This issue doesnt occur in ios4.1 and above.

MPMovie player exit fullscreen programmatically

In MPMoviePlayer when movie player enters in a full screen & when i pressed done button it will exit full screen is there any other method by which i can exit the fullscreen mode programmatically of mpmoview player.?
After looking into the MPMoviePlayerController Class Reference I came across an instance method called:
- (void)setFullscreen:(BOOL)fullscreen animated:(BOOL)animated
And the definition of the method states clearly Causes the movie player to enter or exit full-screen mode.You might want to consider using this method when exiting the fullscreen mode by setting the boolean value of the fullscreen parameter to NO.
Hope this helps!

is there a notification when "slide to unlock" has occurred

I have an iphone game that plays background music using AVSoundPlayer - when someone locks the iphone the music stops which is fine. But when someone unlocks it, I don't want my music to start playing again while you're staring at the "slide to unlock" screen - I want it to start playing once you've actually slid the button and the app is visible again - is there some way to detect this? (I've tried applicationDidBecomeActive but that fires when the phone is unlocked but not when your app is visible yet...)
You could try viewWillAppear.
- (void)applicationDidBecomeActive:(UIApplication *)application;
This sent when your app becomes active
Another answer on SO applicable to your question:
applicationWillTerminate works as long as I don't switch off the iPhone