如何检查设备是否通过airplay连接? [英] How to check if the device is connected via airplay?

查看:119
本文介绍了如何检查设备是否通过airplay连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题要检查我是否连接到airplay设备,以及是否通过镜像或流连接。但是检查需要在视频开始之前完成。



如果视频已经开始,airPlayVideoActive仅返回YES。

   - (BOOL)isAudioSessionUsingAirplayOutputRoute 
{
/ **
*我找不到其他方法来检查是否有与airplay设备的连接
* airPlayVideoActive是NO,只要视频没有启动
*一旦设备连接到airplay设备,此方法就为真
* /
AVAudioSession * audioSession = [AVAudioSession sharedInstance];
AVAudioSessionRouteDescription * currentRoute = audioSession.currentRoute;
for(AVAudioSessionPortDescription * currentPoute.outputs中的outputPort){
if([outputPort.portType isEqualToString:AVAudioSessionPortAirPlay])
返回YES;
}
返回NO;
}

要检查airplay连接是否镜像,您只需检查屏幕数量。

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

如果有一个更好的解决方案,让我知道


I had the problem to check if I am connected to an airplay device and if it is connected via mirroring or streaming. But the check needs to be done before the video started.

airPlayVideoActive only return YES if the video already started.

解决方案

This is my solution

- (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;
}

To check if the airplay connection is mirroring you just have to check the screens count.

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

If there is a better solution, let me know

这篇关于如何检查设备是否通过airplay连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆