1

I am using the MPVolumeview in my video overlay to use the route button and connect to airplay. I hide the MPVolume's volume slider. I trying to resize the overlay to include a frame for the route button only if airplay is available. Previously I had been using an observer on the route button in the MPVolumeView like this :

for (UIView *view in volumeButton.subviews) {
    if ([view isKindOfClass:[UIButton class]]) {
        airplayButton = [view retain];
        [airplayButton addObserver:self forKeyPath:@"alpha" options:NSKeyValueObservingOptionNew context:nil];
    }
}

I then set a boolean property that keeps track of whether the button is visible or not. Recently however I have found on the iPhone 6 that the route button is not consistently showing on videos. I looked back at MPVolumeView and found that there is a property now called areWirelessRoutesAvailable so I've stepped through the code and found that this property is not consistently true. I am setting the MPVolumeView in awakeFromNib and the check on MPVolumeView is in layoutsubviews. Is there a better way to check for airplay availability, is the route button consistently showing a problem with MPVolumeView or am I missing something?

conlaw
  • 23
  • 6

1 Answers1

0

You can add observer for MPVolumeViewWirelessRoutesAvailableDidChangeNotification and resize the overlay when you get the notification.

    - (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);
        // Resize the overlay
    }