Disable AirPlay with MPMoviePlayerController

此生再无相见时 提交于 2019-12-30 08:13:34

问题


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?


回答1:


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.




回答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.




回答3:


@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.



来源:https://stackoverflow.com/questions/7749770/disable-airplay-with-mpmovieplayercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!