是否有任何 public api 来检测 AirPlay 是否可用

Is there any public api to detect AirPlay available or not

我已经实现了 MPVolumeView 以显示 Airplay 选项,但我不知道如何在 Airplay options/sources 不再可用时隐藏 MPVolumeView。

有没有public API可以检测AirPlay option/source可用与否。这样应用程序就可以 hide/show airplay 选项。

注意:我使用的是自定义播放器,而不是默认的 MPMoviePlayerController

谢谢!

我看到了两种可行的方法:

  1. 将 MPVolumeView 的 showsVolumeSlider 设置为 NO,AirPlay 路由按钮选择器“...仅当有可用的 AirPlay 输出设备时才可见。”

来源:https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AirPlayGuide/EnrichYourAppforAirPlay/EnrichYourAppforAirPlay.html

  1. 为 MPVolumeViewWirelessRoutesAvailableDidChangeNotification 添加观察者并隐藏或删除您的子视图。

    - (void)viewWillAppear:(BOOL)animated {
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(handleWirelessRoutesDidChange:)
                                                   name:MPVolumeViewWirelessRoutesAvailableDidChangeNotification object:nil];
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    }
    
    - (void)handleWirelessRoutesDidChange:(NSNotification *)notification {
        NSLog(@"Wireless routes did change: %@", notification);
        // Hide or remove your MPVolumeView
    }
    

除了正确的响应之外 MPVolumeViewWirelessRoutesAvailableDidChangeNotification 它已被弃用 AVRouteDetectorMultipleRoutesDetectedDidChangeNotification