As of iOS 5 we have access to MPNowPlayingInfoCenter
to display info in the lockscreen and in the multimedia controls on the multitasking bar. I have an app that plays local audio files. I want to display info like the artist's name, the album and the artwork on the lockscreen with MPNowPlayingInfoCenter
, but the only way to do this (As far as I know) is to use MPMusicPlayerController
and get nowPlayingItem
... The problem is that MPMusicPlayerController
is used to play iPod Music only, and not locally stored files. Is there a way around this in iOS 5?
Asked
Active
Viewed 6,280 times
6

Alex1987
- 9,397
- 14
- 70
- 92
1 Answers
16
You can create your own NSDictionary and supply that to the MPNowPlayingInfoCenter.
NSArray *keys = [NSArray arrayWithObjects:MPMediaItemPropertyAlbumTitle, MPMediaItemPropertyArtist, ..., nil];
NSArray *values = [NSArray arrayWithObjects:@"Album", @"Artist", ..., nil];
NSDictionary *mediaInfo = [NSDictionary dictionaryWithObjects:values forKeys:keys];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mediaInfo];

steharro
- 1,079
- 8
- 18
-
But how do I get the album name of a locally stored track? Or the artwork? – Alex1987 Mar 13 '12 at 08:31
-
2You will need to read the ID3 tags of the locally stored file. See http://stackoverflow.com/questions/1239460/reading-mp3-information-using-objective-c – steharro Mar 13 '12 at 10:47
-
2You also need to specify that you app receives remote control events: `[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];` – Antonio R. Mar 18 '14 at 10:52
-
Don't forget to `#import
` – sam_smith Sep 21 '17 at 23:27