我已经实现了 MPMusicPlayerController 来播放库中的音乐。当应用程序进入后台时,我暂停它,当它回到前台时,我希望它恢复。它暂停得很好,但从头开始。这是代码...
AppDelegate.m
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self.appMusicPlayer pause];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[self.appMusicPlayer play];
}
主视图控制器.m
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
[self dismissModalViewControllerAnimated: YES];
appdelegate.selectedSongCollection=mediaItemCollection;
appdelegate.appMusicPlayer = [MPMusicPlayerController applicationMusicPlayer];
[appdelegate.appMusicPlayer setQueueWithItemCollection:appdelegate.selectedSongCollection];
[appdelegate.appMusicPlayer play];
[btnStop setHidden:NO];
[btnMusic setHidden:YES];
}
- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker
{
[self dismissModalViewControllerAnimated: YES];
}
当应用程序进入前台时如何恢复它的任何想法?