【问题标题】:MPNowPlayingInfoCenter info doesn't work via USB accessoryMPNowPlayingInfoCenter 信息无法通过 USB 附件工作
【发布时间】:2015-03-20 04:54:16
【问题描述】:

我有一个使用AVPlayer(实际上是AVQueuePlayer)播放音频的应用程序。它设置MPNowPlayingInfoCenter 信息,使用MPRemoteCommandCenter 管理远程命令,并允许背景音频。所有这些功能都可以通过控制中心和锁定屏幕正常工作。当我将手机带入车内时,它也可以与车内的蓝牙接口正常工作。但是,如果我通过 iPhone 6 闪电端口将手机直接插入汽车的立体声音响,它就会严重损坏。它确实会播放音频,但是...

(1) 我的汽车仪表盘上不会显示任何正在播放的信息 (2) 每当我尝试做任何事情时,我的汽车音响都会抛出一堆连接错误。

我手机上的其他应用没有这个问题,所以我认为这不是我的音响的问题。我用的是苹果官方的闪电线,所以也没有关系。

我通过我的 Apple TV 尝试了我的带有 AirPlay 的应用程序,它同样不稳定。我注意到AVPlayer 有一个名为allowsExternalPlayback 的重要属性,如果您只播放音频,则需要将其设置为NO。将该属性设置为NO 后,通过Apple TV 的AirPlay 可以正常工作。我认为这与影响我的汽车的问题相同,但事实并非如此。即使将allowsExternalPlayback 设置为NO,通过我的汽车上的USB 连接播放音频仍然搞砸了。

似乎 (a) AVAudioSession 或 (b) AVPlayer 的配置方式有问题。

我的音频播放器配置非常简单...

self.audioQueue = [AVQueuePlayer queuePlayerWithItems:nil];
self.audioQueue.allowsExternalPlayback = NO;

[self.audioQueue addObserver:self forKeyPath:@"status" options:0 context:kAVPlayerStatusContext];
[self.audioQueue addObserver:self forKeyPath:@"rate" options:0 context:kAVPlayerRateContext];
[self.audioQueue addObserver:self forKeyPath:@"error" options:0 context:kAVPlayerErrorContext];
[self.audioQueue addObserver:self forKeyPath:@"currentItem" options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) context:kAVPlayerCurrentItemContext];

...就像在我的音频会话中...

AVAudioSession *audioSession = [AVAudioSession sharedInstance];

NSError *error;
[audioSession setActive:YES error:&error];
// Error handling code

[audioSession setCategory:AVAudioSessionCategoryPlayback error:&error];
// Error handling code

// Audio session notifications
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self selector:@selector(audioSessionInterruptionNotification:) name:AVAudioSessionInterruptionNotification object:audioSession];
[defaultCenter addObserver:self selector:@selector(audioSessionRouteChangeNotification:) name:AVAudioSessionRouteChangeNotification object:audioSession];
[defaultCenter addObserver:self selector:@selector(audioSessionMediaServicesWereResetNotification:) name:AVAudioSessionMediaServicesWereResetNotification object:audioSession];

是否需要设置其他属性来处理此用例?我能做些什么来调试这里发生的事情?这个是我的。

【问题讨论】:

    标签: objective-c avplayer


    【解决方案1】:

    这里有两个问题...

    1. 我设置 MPNowPlayingInfoPropertyPlaybackQueueIndex 的方式与设置 MPMediaItemPropertyAlbumTrackCount 的方式相同。查看文档后,我意识到MPNowPlayingInfoPropertyPlaybackQueueIndex 是从零开始的,我总是将队列索引设置为 1,队列计数设置为 1。这导致汽车音响根本不显示任何信息。

    2. 1234563速度。我删除了不必要的播放调用,它解决了我的其他问题。出于某种原因,那次通话的效果是汽车音响在我按下暂停按钮后立即发送播放命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-14
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多