MP_EXTERN_CLASS_AVAILABLE(5_0)@interfaceMPNowPlayingInfoCenter : NSObject// Returns the default now playing info center.// The default center holds now playing info about the current application.+(MPNowPlayingInfoCenter*)defaultCenter;// The current now playing info for the center.// Setting the info to nil will clear it.@property(copy)NSDictionary*nowPlayingInfo;@end
MPMediaItemPropertyAlbumTitle//NSStringMPMediaItemPropertyAlbumTrackCount//NSNumber of NSUIntegerMPMediaItemPropertyAlbumTrackNumber//NSNumber of NSUIntegerMPMediaItemPropertyArtist//NSStringMPMediaItemPropertyArtwork//MPMediaItemArtworkMPMediaItemPropertyComposer//NSStringMPMediaItemPropertyDiscCount//NSNumber of NSUIntegerMPMediaItemPropertyDiscNumber//NSNumber of NSUIntegerMPMediaItemPropertyGenre//NSStringMPMediaItemPropertyPersistentID//NSNumber of uint64_tMPMediaItemPropertyPlaybackDuration//NSNumber of NSTimeIntervalMPMediaItemPropertyTitle//NSString
MP_EXTERN_CLASS_AVAILABLE(3_0)@interfaceMPMediaItemArtwork : NSObject// Initializes an MPMediaItemArtwork instance with the given full-size image.// The crop rect of the image is assumed to be equal to the bounds of the // image as defined by the image's size in points, i.e. tightly cropped.-(instancetype)initWithImage:(UIImage*)imageNS_DESIGNATED_INITIALIZERNS_AVAILABLE_IOS(5_0);// Returns the artwork image for an item at a given size (in points).-(UIImage*)imageWithSize:(CGSize)size;@property(nonatomic,readonly)CGRectbounds;// The bounds of the full size image (in points).@property(nonatomic,readonly)CGRectimageCropRect;// The actual content area of the artwork, in the bounds of the full size image (in points).@end
// The elapsed time of the now playing item, in seconds.// Note the elapsed time will be automatically extrapolated from the previously // provided elapsed time and playback rate, so updating this property frequently// is not required (or recommended.)MP_EXTERNNSString*constMPNowPlayingInfoPropertyElapsedPlaybackTimeNS_AVAILABLE_IOS(5_0);// NSNumber (double)// The playback rate of the now playing item, with 1.0 representing normal // playback. For example, 2.0 would represent playback at twice the normal rate.// If not specified, assumed to be 1.0.MP_EXTERNNSString*constMPNowPlayingInfoPropertyPlaybackRateNS_AVAILABLE_IOS(5_0);// NSNumber (double)// The "default" playback rate of the now playing item. You should set this// property if your app is playing a media item at a rate other than 1.0 in a// default playback state. e.g., if you are playing back content at a rate of// 2.0 and your playback state is not fast-forwarding, then the default// playback rate should also be 2.0. Conversely, if you are playing back content// at a normal rate (1.0) but the user is fast-forwarding your content at a rate// greater than 1.0, then the default playback rate should be set to 1.0.MP_EXTERNNSString*constMPNowPlayingInfoPropertyDefaultPlaybackRateNS_AVAILABLE_IOS(8_0);// NSNumber (double)// The index of the now playing item in the application's playback queue.// Note that the queue uses zero-based indexing, so the index of the first item // would be 0 if the item should be displayed as "item 1 of 10".MP_EXTERNNSString*constMPNowPlayingInfoPropertyPlaybackQueueIndexNS_AVAILABLE_IOS(5_0);// NSNumber (NSUInteger)// The total number of items in the application's playback queue.MP_EXTERNNSString*constMPNowPlayingInfoPropertyPlaybackQueueCountNS_AVAILABLE_IOS(5_0);// NSNumber (NSUInteger)// The chapter currently being played. Note that this is zero-based.MP_EXTERNNSString*constMPNowPlayingInfoPropertyChapterNumberNS_AVAILABLE_IOS(5_0);// NSNumber (NSUInteger)// The total number of chapters in the now playing item.MP_EXTERNNSString*constMPNowPlayingInfoPropertyChapterCountNS_AVAILABLE_IOS(5_0);// NSNumber (NSUInteger)
[[UIApplicationsharedApplication]beginReceivingRemoteControlEvents]//返回值根据需要返回,一般情况下返回MPRemoteCommandHandlerStatusSuccess即可[[MPRemoteCommandCentersharedCommandCenter].playCommandaddTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent*_Nonnullevent){// playreturnMPRemoteCommandHandlerStatusSuccess;}];[[MPRemoteCommandCentersharedCommandCenter].pauseCommandaddTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent*_Nonnullevent){// pausereturnMPRemoteCommandHandlerStatusSuccess;}];[[MPRemoteCommandCentersharedCommandCenter].togglePlayPauseCommandaddTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent*_Nonnullevent){// play or pausereturnMPRemoteCommandHandlerStatusSuccess;}];
If your app plays audio or video content, you might want it to respond to remote control events that originate from either transport controls or external accessories. (External accessories must conform to Apple-provided specifications.) iOS converts commands into UIEvent objects and delivers the events to an app. The app sends them to the first responder and, if the first responder doesn’t handle them, they travel up the responder chain.
// If nil is specified for principalClassName, the value for NSPrincipalClass from the Info.plist is used. If there is no// NSPrincipalClass key specified, the UIApplication class is used. The delegate class will be instantiated using init.UIKIT_EXTERNintUIApplicationMain(intargc,char*argv[],NSString*principalClassName,NSString*delegateClassName);