在通话时处理来自 AirPods 的播放/暂停命令

问题描述 投票:0回答:1

有什么方法可以在进行来自同一应用程序的音频/视频通话时处理耳机命令吗?

我正在开发使用 CallKit 拨打电话的应用程序,最近我收到了一项任务,允许用户在 AirPods 上双击(下一个曲目命令)时将通话静音。目前,任何操作都会导致呼叫结束,并且我找不到修改此行为的解决方法。 FaceTime 和本机通话也会发生同样的情况。

到目前为止,我尝试使用 MPRemoteCommandCenter 来响应远程命令,例如

import MediaPlayer
 
let remoteCommandCenter = MPRemoteCommandCenter.shared()
Log.i("Setting up a remote command event handler.") 
remoteCommandCenter.nextTrackCommand.addTarget { (action: MPRemoteCommandEvent) in
  Log.i("Detected nextTrackCommand: \(action)") // Never is printed
  return .success
}
remoteCommandCenter.nextTrackCommand.isEnabled = true
assert(audioSession.category == .playAndRecord)

我所有的想法都失败了,因为回调没有被调用。此时,我开始认为这是硬件限制。

objective-c swift callkit mpremotecommandcenter
1个回答
0
投票

letremoteCommandCenter = MPRemoteCommandCenter.shared()之后,让它播放,会有回调。 代码如下(OC): MPNowPlayingInfoCenter.defaultCenter.playbackState = MPNowPlayingPlaybackStatePlaying;

© www.soinside.com 2019 - 2024. All rights reserved.