Just add observer for MPAVControllerPlaybackStateChangedNotification.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackStateDidChange:)
name:@"MPAVControllerPlaybackStateChangedNotification"
object:nil];
then start listening:
- (void)playbackStateDidChange:(NSNotification *)note
{
NSLog(@"note.name=%@ state=%d", note.name, [[note.userInfo objectForKey:@"MPAVControllerNewStateParameter"] intValue]);
int playbackState = [[note.userInfo objectForKey:@"MPAVControllerNewStateParameter"] intValue];
switch (playbackState) {
case 1: //end
;
break;
case 2: //start
;
break;
default:
break;
}
}
Explore other states if you're curious. Additionally everyone interested in bunch of other notifications can register to see all:
CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(),
NULL,
noteCallbackFunction,
NULL,
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
then check what's coming on:
void noteCallbackFunction (CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
NSLog(@"notification name: %@", name);
NSLog(@"notification info: %@", userInfo);
}
Have fun!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…