3

我正在使用 AudioKit 来管理我的应用程序中的声音引擎。我认为 AudioKit 的设置覆盖了某些东西,我无法获得锁屏音频控制。这是我目前的代码:

//Configure media control center
    UIApplication.shared.beginReceivingRemoteControlEvents()
    let commandCenter = MPRemoteCommandCenter.shared()

    commandCenter.pauseCommand.addTarget { (event) -> MPRemoteCommandHandlerStatus in
        //Update your button here for the pause command
        return .success
    }

    commandCenter.playCommand.addTarget { (event) -> MPRemoteCommandHandlerStatus in
        //Update your button here for the play command
        return .success
    }

我在一个设置我所有 AudioKit 设置的函数中有这个,但它不起作用。使用 AudioKit 进行锁屏音频控制是否有特殊程序?

4

3 回答 3

1

你得在appdelegate中写这些代码来实现:</p>

do {
    try AVAudioSession.sharedInstance().setActive(true)
    try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
}catch{

}
UIApplication.shared.beginReceivingRemoteControlEvents()
于 2018-03-15T01:43:58.797 回答
0

请记住,禁用它很重要.mixWithOthers

于 2021-04-26T07:26:23.450 回答
0
You have to rewrite this methord:
//MARK:-音乐播放相应后台状态
override func remoteControlReceived(with event: UIEvent?) {
    if (event?.type == .remoteControl) {
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: Configs.remotePlayCotrolNotificaation), object: nil, userInfo: ["event":event!])
    }
}
于 2018-03-19T03:15:30.553 回答