簡體   English   中英

錄制視頻時的音頻音量

[英]Volume of audio while recording video

因此,經過大量搜索,我找到了允許在錄制視頻的同時播放背景音頻的代碼塊。 我在下面粘貼了上述代碼塊。

fileprivate func setBackgroundAudioPreference() {
    guard allowBackgroundAudio == true else {
        return
    }

    guard audioEnabled == true else {
        return
    }

    do{
        if #available(iOS 10.0, *) {
            try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [.mixWithOthers, .allowBluetooth, .allowAirPlay, .allowBluetoothA2DP])
        } else {
            let options: [AVAudioSession.CategoryOptions] = [.mixWithOthers, .allowBluetooth]
            let category = AVAudioSession.Category.playAndRecord
            let selector = NSSelectorFromString("setCategory:withOptions:error:")
            AVAudioSession.sharedInstance().perform(selector, with: category, with: options)
        }
        try AVAudioSession.sharedInstance().setActive(true)
        session.automaticallyConfiguresApplicationAudioSession = false
    }
    catch {
        print("[SwiftyCam]: Failed to set background audio preference")

    }
}

但是,我有一個小問題。 出於某種原因,當相機加載時,背景音量會降低。 當我使用 instagram 錄制視頻時,音頻不會減少並且它仍然會錄制有什么方法可以更改我當前的代碼塊以在使用視頻錄制時不降低音量?

我閱讀了文檔,顯然 .duckOthers 選項應該是減少音量的唯一選項。 但這個也一樣

好的,所以我在深入研究一些文檔后找到了答案。

更新后的代碼張貼在下面。 您所要做的就是設置 .defaultToSpeaker 選項

fileprivate func setBackgroundAudioPreference() {
    guard allowBackgroundAudio == true else {
        return
    }

    guard audioEnabled == true else {
        return
    }

    do{
        if #available(iOS 10.0, *) {
            try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [.mixWithOthers, .allowBluetooth, .allowAirPlay, .allowBluetoothA2DP,.defaultToSpeaker])
        } else {
            let options: [AVAudioSession.CategoryOptions] = [.mixWithOthers, .allowBluetooth]
            let category = AVAudioSession.Category.playAndRecord
            let selector = NSSelectorFromString("setCategory:withOptions:error:")
            AVAudioSession.sharedInstance().perform(selector, with: category, with: options)
        }
        try AVAudioSession.sharedInstance().setActive(true)
        session.automaticallyConfiguresApplicationAudioSession = false
    }
    catch {
        print("[SwiftyCam]: Failed to set background audio preference")

    }
}

暫無
暫無

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

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