-0.4 C
New York
Saturday, February 22, 2025

xcode – MPNowPlayingInfoCenter data will not be displayed on iOS 8


I am growing a music utility, which ought to play music within the background.

I exploit the MPMoviePlayerController to play the music. My code to provoke the MPMoviePlayerController:

NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/music.m4a"];
NSError* err;
self.participant = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:resourcePath]];
if (err) {
    NSLog(@"ERROR: %@", err.localizedDescription);
}
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
[session setActive:YES error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self.player setShouldAutoplay:NO];
[self.player setControlStyle: MPMovieControlStyleEmbedded];
self.participant.view.hidden = YES;
[self.player prepareToPlay];

After I execute [self.player play]; the music begins.
However I additionally wish to show the identify of the tune, the identify of the album and the album paintings within the LockScreen and the ControlCenter. I am utilizing the next code:

Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
    if (playingInfoCenter) {
        NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
        MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imageNamed:@"artwork.png"]];
        [songInfo setObject:@"SongName" forKey:MPMediaItemPropertyTitle];
        [songInfo setObject:@"ArtistName" forKey:MPMediaItemPropertyArtist];
        [songInfo setObject:@"AlbumTitle" forKey:MPMediaItemPropertyAlbumTitle];
        [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
    }

However nothing will get displayed within the LockScreen. It would not get displayed within the ControlCenter both.

How can I remedy my downside? I did not discover something on the web.

Thanks upfront, Fabian.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles