Step 1
When your application go to background or goes to inactive state, you need to save the current playback time.
You can get the currentTime
by using currentTime property of AVAudioPlayer
You can save the value to NSUserDefaults for persistence
You can use the following delegate to detect the application inactive state
- (void)applicationWillResignActive:(UIApplication *)application
Step 2
When your come active, you can retrieve the data from the NSUserDefaults
and using that you can play it from the time where your music stopped.
For detecting the state, you need to use:
- (void)applicationDidBecomeActive:(UIApplication *)application
You can set the currentTime
property for restarting the playing from the position where you stopped it.