与AVAudioPlayer MPNowPlayingInfoCenter兼容? [英] Is MPNowPlayingInfoCenter compatible with AVAudioPlayer?

查看:330
本文介绍了与AVAudioPlayer MPNowPlayingInfoCenter兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始用 - 播放 AVAudioPlayer ,然后设置nowPlaying词典是这样的:

I start -play with AVAudioPlayer, and then set the nowPlaying dictionary like this:

NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
        
MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imagedNamed:@"AlbumArt"]];
[songInfo setObject:@"Audio Title" forKey:MPMediaItemPropertyTitle];
[songInfo setObject:@"Audio Author" forKey:MPMediaItemPropertyArtist];
[songInfo setObject:@"Audio Album" forKey:MPMediaItemPropertyAlbumTitle];
[songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];

在锁屏始终显示一个暂停按钮。我正确地接收到遥控器的事件,我可以切换播放/通过遥控器事件暂停,但锁屏不断出现暂停,甚至当它播放。

The lock screen always shows a pause button. I receive the remote control events correctly and I can toggle play/pause through the remote control events, but the lock screen keeps showing "pause" even when it is playing.

现在我见过的MPMoviePlayerController这项工作。谁能解释如何在MPNowPlayingInfoCenter确定是否应显示播放或暂停按钮?

Now I seen this work with MPMoviePlayerController. Can someone explain how does the MPNowPlayingInfoCenter determine if it should show a play or a pause button?

推荐答案

你有没有设置正确的 AVAudioSessionCategory AudioSession ?它需要 AVAudioSessionCategoryPlayback 我相信得到它的工作。

Have you set the correct AVAudioSessionCategory on the AudioSession? it needs to be AVAudioSessionCategoryPlayback I believe to get it to work.

这篇关于与AVAudioPlayer MPNowPlayingInfoCenter兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆