如何在ios7上使用AVPlayer在后台播放音乐时在遥控器上设置标题

时间:2013-10-11 03:51:42

标签: ios7 title avplayer remote-control

在使用AVPlayer播放背景音乐的过程中,如何在ios 7上的遥控器上设置标题音乐?

1 个答案:

答案 0 :(得分:2)

你想要的课程是MPNowPlayingInfoCenter。

创建一个值字典并将它们传递给它,就像这样......

NSMutableDictionary *info=[NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Song title",@"Artist name",nil] forKeys:[NSArray arrayWithObjects: MPMediaItemPropertyTitle,MPMediaItemPropertyArtist,nil]];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:info];

确保导入以下内容:

#import <MediaPlayer/MPNowPlayingInfoCenter.h>
#import <MediaPlayer/MPMediaItem.h>
#import <MediaPlayer/MPMediaQuery.h>

字典中的键如下:

MPMediaItemPropertyAlbumTitle
MPMediaItemPropertyAlbumTrackCount
MPMediaItemPropertyAlbumTrackNumber
MPMediaItemPropertyArtist
MPMediaItemPropertyArtwork
MPMediaItemPropertyComposer
MPMediaItemPropertyDiscCount
MPMediaItemPropertyDiscNumber
MPMediaItemPropertyGenre
MPMediaItemPropertyPersistentID
MPMediaItemPropertyPlaybackDuration
MPMediaItemPropertyTitle
MPNowPlayingInfoPropertyElapsedPlaybackTime
MPNowPlayingInfoPropertyPlaybackRate;
MPNowPlayingInfoPropertyPlaybackQueueIndex;
MPNowPlayingInfoPropertyPlaybackQueueCount;
MPNowPlayingInfoPropertyChapterNumber;
MPNowPlayingInfoPropertyChapterCount;

源:

https://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPNowPlayingInfoCenter_Class/Reference/Reference.html