iosiphoneavplayeripod

How to set metadata of sound track (artwork, album, etc.) on the lock screen iOS?


I'm trying to develop a simple audio player app for iPhone or iPad. I'm made working on the background mode and controlling playback on the lock screen, but I can't set data about current music track (artwork, album, etc.) on the lock screen like it work on default iOS music player. How can i accomplish this? Any help is appreciated in advance, Thank You.


Solution

  • I solved this problem. In order to show the metadata about sound track (artwork, album, title, etc.) on the lock screen iOS you should use MPNowPlayingInfoCenter class. For example:

        MPMediaItemArtwork *albumArtwork = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"artwork.png"]];
        NSDictionary *nowPlayingInfo = @{MPMediaItemPropertyTitle: @"Title",
                                         MPMediaItemPropertyArtist: @"Artist",
                                         MPMediaItemPropertyAlbumTitle: @"Album",
                                         MPMediaItemPropertyArtwork: albumArtwork};
        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nowPlayingInfo];