【发布时间】:2015-06-16 03:55:56
【问题描述】:
我在检查我是否连接到播放设备以及它是否通过镜像或流媒体连接时遇到问题。但需要在视频开始之前进行检查。
airPlayVideoActive 仅在视频已经开始时才返回 YES。
【问题讨论】:
标签: ios objective-c iphone ipad airplay
我在检查我是否连接到播放设备以及它是否通过镜像或流媒体连接时遇到问题。但需要在视频开始之前进行检查。
airPlayVideoActive 仅在视频已经开始时才返回 YES。
【问题讨论】:
标签: ios objective-c iphone ipad airplay
这是我的解决方案
- (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
}
如果有更好的解决方案,请告诉我
【讨论】:
Swift 版本:
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
}
【讨论】:
如果你使用的是 AVPlayer,它有属性isExternalPlaybackActive 可以帮助你
【讨论】: