Disable AirPlay with MPMoviePlayerController
Asked Answered
I

3

10

I have an instance of a MPMoviePlayerController which is being used to display some live streaming video on an iPhone app. This is working fine, however I wish to remove all AirPlay functionality.

To be sure, I specifically disable AirPlay like so:

if([self.moviePlayerController respondsToSelector:@selector(setAllowsAirPlay:)]) {
    self.moviePlayerController.allowsAirPlay = NO;
}

However, even with this code, I still see the AirPlay icon on the video controls. If I select this, and select my AppleTV, only the audio is sent over AirPlay - the video continues to play within the app. If I set allowsAirPlay to YES, both the video & audio are sent over AirPlay.

Does anyone know why this happens? Is this a feature of the OS, to allows allow the audio to be sent over AirPlay?

Immensurable answered 13/10, 2011 at 5:18 Comment(5)
did you try to set useApplicationAudioSession = NO; ?Bottali
I have now - didn't seem to make any difference I'm afraid.Immensurable
Did you set allowsAirPlay before setting the player's content URL?Caenogenesis
This is a related question #5665836Caenogenesis
No, as I'm using the initWithContentURL method to initialise the MPMoviePlayerController. I guess I could try it?Immensurable
I
4

It turns out that the AirPlay icon is still visible (and should remain visible) so that audio can be routed to any suitable device, eg. a Bluetooth headset. Attempting to hide the icon is considered bad practice.

Immensurable answered 15/12, 2011 at 6:28 Comment(4)
Pretty old question; but any chance you have a link to Apple documentation supporting this?Countermand
Sorry, no - I actually got the answer from an Apple engineer at one of their Tech Talks. If you think about it logically it makes sense. Those who want to use a Bluetooth headset or speakers should always be able to use them, as they may be hard of hearing etc.Immensurable
Thanks. I think that makes sense, there is just concern about content licensing.Countermand
@Countermand - Sorry really old question etc.. Did you manage to track down any documentation for this? Im about to embark on the same challenge, even a WWDC reference would be good :)Castor
G
2

I known its an old question but still maybe this will help someone else.
Apple has the following api to hide the route button (AirPlay)

@property (nonatomic) BOOL showsRouteButton NS_AVAILABLE_IOS(4_2);  // Default is YES.

Hope this helps anyone.

Globefish answered 6/8, 2014 at 11:51 Comment(0)
P
0

@Philip K, your hint almost solved this for me, debugging some four year old code. showsRouteButton isn't a property on the MPMoviePlayerController, and I tried setting:

myMPMoviePlayer.allowsAirPlay = NO;

But this did nothing...

And we are using custom controls for our video player, and found that the route button is a part of the MPVolumeView, and your trick applies there:

MPVolumeView * vView = [[MPVolumeView alloc] initWithFrame: bounds];
vView.showsRouteButton = NO;

Bingo! Thanks.

Pithos answered 18/3, 2015 at 23:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.