簡體   English   中英

使用 AudioKit 鎖定屏幕中的音頻控制

[英]Audio controls in lock screen with AudioKit

我正在使用 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 進行鎖屏音頻控制的特殊程序?

你必須在 appdelegate 中編寫這些代碼才能實現:

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

}
UIApplication.shared.beginReceivingRemoteControlEvents()
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!])
    }
}

請記住,禁用.mixWithOthers很重要

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM