【问题标题】:How to check if the device is connected via airplay?如何检查设备是否通过airplay连接?
【发布时间】:2015-06-16 03:55:56
【问题描述】:

我在检查我是否连接到播放设备以及它是否通过镜像或流媒体连接时遇到问题。但需要在视频开始之前进行检查。

airPlayVideoActive 仅在视频已经开始时才返回 YES。

【问题讨论】:

    标签: ios objective-c iphone ipad airplay


    【解决方案1】:

    这是我的解决方案

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

    如果有更好的解决方案,请告诉我

    【讨论】:

    • 我需要在所有应用程序中检查它,以便我将在哪里编写此代码。我对此感到困惑,请帮助。 :)
    【解决方案2】:

    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
    }
    

    【讨论】:

      【解决方案3】:

      如果你使用的是 AVPlayer,它有属性isExternalPlaybackActive 可以帮助你

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-04
        相关资源
        最近更新 更多