0

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!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Karamjeet Singh
  • 460
  • 1
  • 5
  • 16

2 Answers2

1

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
    }
    
  • Thanks @Brady White for this information but If I log notification ( Device connected or disconnected ) then this information display
    NSConcreteNotification 0x13c5dccf0 {name = MPVolumeViewWirelessRoutesAvailableDidChangeNotification; object = >}
    I am not able to get any information related what happen to airplay device which was connected and is currently connect
    – Karamjeet Singh Jun 15 '16 at 03:07
  • **My case study:** _Case 1)_ When app launches, there is no AirPlay indicator visible; however in the operating system, I see two AppleTV devices available. If I turn on a bluetooth speaker that has already been paired with my phone, the speaker connects and the AirPlay icon becomes visible. If I click on the AirPlay icon, I see the bluetooth speaker and the two AppleTV devices in the list. If I turn off the bluetooth speaker, the Airplay icon disappears. My next case in next comment: – Karamjeet Singh Jun 15 '16 at 03:14
  • _Case 2)_ When app launches, there is no AirPlay indicator visible; however in the operating system, I see two AppleTV devices available. If I turn on a bluetooth speaker that has already been paired with my phone, the speaker connects and the AirPlay icon becomes visible. If I click on the AirPlay icon, I see the bluetooth speaker and the two AppleTV devices in the list. If I now select one of the AppleTV devices, music is routed appropriately and the AirPlay remains visible. _P.T.O _ – Karamjeet Singh Jun 15 '16 at 03:16
  • If I turn off the bluetooth speaker while I am connected to an AppleTV, the AirPlay icon still remains visible. If I press the AirPlay icon and select "phone" as the output, the AirPlay icon disappears. The functionality I would like: AirPlay icon IS visible when there are AirPlay devices on the network OR there are bluetooth speakers available. AirPlay icon is NOT visible if the only audio output option is "phone" – Karamjeet Singh Jun 15 '16 at 03:17
  • Thanks for your help. Please go through with my all the above comments and let me know how I can solve my problem. – Karamjeet Singh Jun 15 '16 at 03:19
  • Hi Karam, what you've described in your comments appears to be a bug. I suggest filing a radar. http://stackoverflow.com/questions/13699915/ios-missing-audio-routes-sources-in-mpvolumeview is also related as it suggests that AirPlay devices are only shown which are compatible with the audio or video in use. However since you had the Apple TVs show up only when the bluetooth speaker was connected, that would suggest the Apple TVs are capable of routing the output. I was able to answer your original question, please mark as accepted if you find it sufficient. – Brady White Jun 16 '16 at 16:21
  • I also suggest moving your case study to another question so it can be answered separately. – Brady White Jun 16 '16 at 17:14
0

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