ios - iOS 7 上的 MPNowPlayingInfoCenter AVPlayer

标签 ios ios7 avplayer avqueueplayer mpnowplayinginfocenter

我正在制作一个流式传输音乐的应用程序。我正在尝试在锁定屏幕上显示元数据(标题、艺术家和艺术作品图像)。

MPNowPlayingInfoCenter 似乎可以很好地与 MediaPlayer.framework 配合使用,但我无法在 iOS 7 上与 AVPlayer 配合使用。

由于AVAudioSession,播放器在后台模式下运行良好:

AVAudioSession *session = [AVAudioSession sharedInstance];    
[session setCategory:AVAudioSessionCategoryPlayback error:&error];
[session setActive:YES error:&error];

这是我在锁屏上显示元数据的代码(不起作用):

Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

if (playingInfoCenter)
{
    NSDictionary *nowPlaying = @{MPMediaItemPropertyArtist: currentTrack.artist,
                                 MPMediaItemPropertyAlbumTitle: currentTrack.title};

    [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nowPlaying];
}        

如有任何帮助,我们将不胜感激!

感谢阅读本文:)

最佳答案

找到了我的问题的答案!

使用背景音时,必须指定你的应用可以接收远程控制事件:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

关于ios - iOS 7 上的 MPNowPlayingInfoCenter AVPlayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20665006/

相关文章:

ios - 渲染后更新单元格高度

ios - 在 iOS 7 中使用 applicationDidEnterBackground : 应用程序进入后台时无法更新 View

ios7 - ios7中什么情况下应用程序不会在设备上有收据

objective-c - 当 UIView 框架更改时, View 内的 AVPlayer 层不会调整大小

iOS - 如何在 AVPlayer 中实现 seektotime(从 URL 播放歌曲)?

ios - 如何在 iOS 6 中禁用 UITableView 水平滚动?

ios - 为什么字体是可选的?

ios - 创建一个每秒运行的计时器,在第二个?

iphone - iOS 7 表格 View 无法自动调整内容插入

ios - 捕获多个帧并像回旋镖一样准备视频