//Register self for remote notifications of play/pause toggle
//(i.e. when user backgrounds app, double-taps home,
//then swipes right to reveal multimedia control buttons).
//See MyWindow.h for more info.
Add this Notification Center where to detect playback
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toggling_Playback) name:@"TogglePlayPause" object:nil];
- (void)toggling_Playback {
(self.player.isPlaying ? [self.player pause] : [self.player play]);
}
AVAudioPlayerDelegate protocol methods:
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)p successfully:(BOOL)flag {
[self.player stop];
[self ffButtonWasPressed];
}
- (void)audioPlayerBeginInterruption:(AVAudioPlayer *)player {
//In real app, may persist this to NSUserDefaults to act on after interruption ends
//or app resumes.
NSLog(@"Interruption began");
}
//Note: this form is only for iOS >= 4.0. See docs for pre-4.0.
- (void)audioPlayerEndInterruption:(AVAudioPlayer *)player withFlags:(NSUInteger)flags {
NSLog(@"Interruption ended");
//restart playback if flag indicates we should resume
if (flags & AVAudioSessionInterruptionFlags_ShouldResume) {
[self toggling_Playback];
}
}
如果您还有任何的疑问:仔细查阅此链接 http://www.allappsdevelopers.com/TopicDetail.aspx?TopicID=99cb8bf0-91ac-4c41-a903-2dc744444b7a
你有没有发现这方面的任何解决方案? – 2015-07-01 10:58:41