仅当视频在我的应用程序中取消静音时才停止其他应用程序的背景音乐 Swift UIKit

stop background music of other app only when the video is unmuted in my app Swift UIKit

applicationDidBecomeActive

 do {
        try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: .duckOthers)
    } catch let error {
        print(error.localizedDescription)
    }

我的app播放视频时其他app的声音不会停止,只是降低音量,这就是我想要的

self.player.isMuted = true

视频将以静音模式播放, 我想实现这一点当我取消视频静音时,其他应用程序的音频应该停止 在 Facebook 点赞

我尝试在点击静音/取消静音按钮时设置:

do {
        try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: .interruptSpokenAudioAndMixWithOthers)
    } catch let error {
        print(error.localizedDescription)
    }

当应用播放其音频但它不起作用时,暂停来自其他会话的口述音频内容 即使我设置

try AVAudioSession.sharedInstance().setActive(true)

默认行为是停止其他应用程序的音频。如果您想要该默认行为,请不要传递 .duckOthers.interruptSpokenAudioAndMixWithOthers。这两个都表示您不想停止其他音频。