【问题标题】:How do I stop AirPlay audio with AVPlayer?如何使用 AVPlayer 停止 AirPlay 音频?
【发布时间】:2022-03-16 03:27:56
【问题描述】:

我正在开发一个 iOS 应用程序,由于我们不会在这里讨论的原因,它有时希望在远程设备上禁用 AirPlay 播放,并且只在 iOS 设备上本地播放视频,而不管用户的设置如何。

我正在使用 AVPlayer 播放视频,目前无法协商。

我将 iOS 5.0+ AVPlayer 属性 allowAirPlayVideo 设置为 NO,这会阻止视频远程播放。但如果用户在 iOS 设备上开启了 AirPlay,音频仍会通过远程设备进行流式传输。

我在 Apple 的文档中没有看到类似的 allowAirPlayAudio 标志,我也没有在其他任何地方发现过这个问题。

例如,这个 Stack Overflow 问题:

Audio Output Routes for AirPlay

谈论“USB 音频附件中的音频输出目的地”,这听起来不像我需要的。

我不想只是关闭音频,我希望音频继续通过我的 iOS 设备播放。

我错过了什么吗?谢谢!

【问题讨论】:

    标签: ios airplay


    【解决方案1】:

    可能与How to detect if a bluetooth headset plugged or not IOS 8? 重复

    我知道这是一个老问题,但是嘿,它可能对某些人有所帮助

    【讨论】:

      【解决方案2】:

      这是我断开音频的操作,mConnectDisconnect 是布尔参数。

      allowsExternalPlayback 将从空中播放中删除图像并在您的设备屏幕上播放。

      AVAudioSessionCategoryOptionDefaultToSpeaker 这个选项可以让你改变设备的音频

      AVAudioSession* session = [AVAudioSession sharedInstance];
          self.player.allowsExternalPlayback = mConnectDisconnect;
          if(allowsExternalPlayback){
                  [session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowAirPlay error:nil];
              
          }else{
              [session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
          }
      [session setActive:true error:nil];
      }
          
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-06-30
        • 1970-01-01
        • 2016-03-17
        • 1970-01-01
        • 1970-01-01
        • 2020-06-06
        • 1970-01-01
        相关资源
        最近更新 更多