我有一个音乐应用程序。将歌曲信息和音乐控件显示在锁定屏幕中的最佳方式是什么,如SoundCloud - 请参阅(http://cl.ly/image/1a1H041A1Z34)
非常感谢!
答案 0 :(得分:6)
非常有用的指南 - Lock screen “Now Playing” with MPNowPlayingInfoCenter;
这仅适用于iOS 5+,并且完成了类似的操作。
- (void)setupNowPlayingInfoCenter:(MPMediaItem *)currentSong
{
NSString *ver = [[UIDevice currentDevice] systemVersion];
CGFloat version = 4.0;
if ([ver length] >= 3)
{
version = [[ver substringToIndex:3] floatValue];
}
if (version >= 5.0)
{
MPMediaItemArtwork *artwork = [currentSong valueForProperty:MPMediaItemPropertyArtwork];
MPNowPlayingInfoCenter *infoCenter = [MPNowPlayingInfoCenter defaultCenter];
if (currentSong == nil)
{
infoCenter.nowPlayingInfo = nil;
return;
}
infoCenter.nowPlayingInfo = [NSDictionary dictionaryWithObjectsAndKeys:
[currentSong valueForKey:MPMediaItemPropertyTitle], MPMediaItemPropertyTitle,
[currentSong valueForKey:MPMediaItemPropertyArtist], MPMediaItemPropertyArtist,
[currentSong valueForKey:MPMediaItemPropertyAlbumTitle], MPMediaItemPropertyAlbumTitle,
[currentSong valueForKey:MPMediaItemPropertyAlbumTrackCount], MPMediaItemPropertyAlbumTrackCount,
[currentSong valueForKey:MPMediaItemPropertyAlbumTrackNumber], MPMediaItemPropertyAlbumTrackNumber,
artwork, MPMediaItemPropertyArtwork,
[currentSong valueForKey:MPMediaItemPropertyComposer], MPMediaItemPropertyComposer,
[currentSong valueForKey:MPMediaItemPropertyDiscCount], MPMediaItemPropertyDiscCount,
[currentSong valueForKey:MPMediaItemPropertyDiscNumber], MPMediaItemPropertyDiscNumber,
[currentSong valueForKey:MPMediaItemPropertyGenre], MPMediaItemPropertyGenre,
[currentSong valueForKey:MPMediaItemPropertyPersistentID], MPMediaItemPropertyPersistentID,
[currentSong valueForKey:MPMediaItemPropertyPlaybackDuration], MPMediaItemPropertyPlaybackDuration,
[NSNumber numberWithInt:self.mediaCollection.nowPlayingIndex + 1], MPNowPlayingInfoPropertyPlaybackQueueIndex,
[NSNumber numberWithInt:[self.mediaCollection count]], MPNowPlayingInfoPropertyPlaybackQueueCount, nil];
}
}
下次尝试使用搜索: