相关疑难解决方法(0)

xcode - iOS 8上不显示MPNowPlayingInfoCenter信息

我正在开发一个应该在后台播放音乐的音乐应用程序.

我用它MPMoviePlayerController来播放音乐.我的代码启动MPMoviePlayerController:

NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/music.m4a"];
NSError* err;
self.player = [[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.player.view.hidden = YES;
[self.player prepareToPlay];
Run Code Online (Sandbox Code Playgroud)

当我执行[self.player play];音乐开始.但我还想在LockScreen和ControlCenter中显示歌曲名称,专辑名称和专辑插图.我正在使用以下代码:

Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
    if (playingInfoCenter) {
        NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
        MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage …
Run Code Online (Sandbox Code Playgroud)

xcode mpmovieplayercontroller audio-player lockscreen ios

6
推荐指数
2
解决办法
7141
查看次数