Karamjeet Singh
Karamjeet Singh

Reputation: 490

Is there any public api to detect AirPlay available or not

I have implement the MPVolumeView to show Airplay option but I don't know how to hide MPVolumeView if Airplay options/sources are no longer available.

Is there any public API which can detecting AirPlay option/source are available or not. So that application can hide/show the airplay option.

NOTE: I am using custom player not the default MPMoviePlayerController

Thanks!

Upvotes: 0

Views: 1057

Answers (2)

MrRobot
MrRobot

Reputation: 309

In addition to the correct response the MPVolumeViewWirelessRoutesAvailableDidChangeNotification it's been deprecated for this one AVRouteDetectorMultipleRoutesDetectedDidChangeNotification

Upvotes: 0

Brady White
Brady White

Reputation: 36

I see two approaches that would work:

  1. Set MPVolumeView's showsVolumeSlider to NO and the AirPlay route button picker "...is visible only when there is an AirPlay output device available."

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

  1. Add observer for MPVolumeViewWirelessRoutesAvailableDidChangeNotification and hide or remove your subview.

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

Upvotes: 1

Related Questions