我有问题要检查我是否连接到airplay设备,以及是否通过镜像或流连接。但是检查需要在视频开始之前完成。
如果视频已经开始,airPlayVideoActive仅返回YES。
答案 0 :(得分:17)
这是我的解决方案
- (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;
}
要检查airplay连接是否正在镜像,您只需检查屏幕数量。
if ([[UIScreen screens] count] < 2)) {
//streaming
}
else {
//mirroring
}
如果有更好的解决方案,请告诉我
答案 1 :(得分:0)
快速版本:
var isAudioSessionUsingAirplayOutputRoute: Bool {
let audioSession = AVAudioSession.sharedInstance()
let currentRoute = audioSession.currentRoute
for outputPort in currentRoute.outputs {
if outputPort.portType == AVAudioSessionPortAirPlay {
return true
}
}
return false
}
并检查屏幕计数:
if UIScreen.screens.count < 2 {
//streaming
} else {
//mirroring
}