How to check if the device is connected via airplay?

前端 未结 2 512
抹茶落季
抹茶落季 2021-02-01 11:15

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.

2条回答
  •  时光说笑
    2021-02-01 11:55

    Swift version:

    var isAudioSessionUsingAirplayOutputRoute: Bool {
    
        let audioSession = AVAudioSession.sharedInstance()
        let currentRoute = audioSession.currentRoute
    
        for outputPort in currentRoute.outputs {
            if outputPort.portType == AVAudioSessionPortAirPlay {
                return true
            }
        }
    
        return false
    }
    

    And checking the screen count:

    if UIScreen.screens.count < 2 {
        //streaming
    } else {
        //mirroring
    }
    

提交回复
热议问题