如何检查设备是否通过播放连接?

我遇到了问题,请检查我是否连接到AirPlay设备,以及是否通过镜像或stream媒体连接。 但是检查需要在video开始之前完成。

airPlayVideoActive只在video已经开始的情况下返回YES。

这是我的解决scheme

- (BOOL)isAudioSessionUsingAirplayOutputRoute { /** * I found no other way to check if there is a connection to an airplay device * airPlayVideoActive is NO as long as the video hasn't started * and this method is true as soon as the device is connected to an airplay device */ AVAudioSession* audioSession = [AVAudioSession sharedInstance]; AVAudioSessionRouteDescription* currentRoute = audioSession.currentRoute; for (AVAudioSessionPortDescription* outputPort in currentRoute.outputs){ if ([outputPort.portType isEqualToString:AVAudioSessionPortAirPlay]) return YES; } return NO; } 

要检查播放连接是否镜像,您只需检查屏幕计数。

 if ([[UIScreen screens] count] < 2)) { //streaming } else { //mirroring } 

如果有更好的解决scheme,让我知道