Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AirPlay support, MPMoviePlayerController and MPVolumeView relation

I am developing an iPhone application that has support for video play. I am using MPMoviePlayerController with custom controls for playing the video. For this purpose I have set control style of MPMoviePlayerController to MPMovieControlStyleNone.

I would like to support AirPlay feature for the video being played. As per the documentation, we have to set the 'allowsAirPlay' property of MPMoviePlayerController to YES to enable AirPlay feature. How can I display the AirPlay button on my player UI if I am using MPMoviePlayerController with custom controls?

I have tried the following:

  1. Instantiated MPVolumeView
  2. Set the showsRouteButton and showsVolumeSlider properties of MPVolumeView to NO to hide the volume slider and route button
  3. Added MPVolumeView on my custom player View

I have not given the reference of MPVolumeView and MPMoviePlayerController to each other. But, if 'allowsAirPlay' of MPMoviePlayerController is set to YES then AirPlay button gets displayed on MPVolumeView. How are MPVolumeView and MPMoviePlayerController related? What is the connection between these two classes which are created independently?

like image 249
spd Avatar asked Apr 20 '11 13:04

spd


3 Answers

Since the MPMoviePlayerController only allows you to play one video at a time, the MediaPlayer framework always knows the video that's playing. That's how MPVolumeView knows about the MPMoviePlayerController. I have no official docs, but I imagine it's baked into the framework this way.

Since there are probably a lot of checks and balances going on (and they loves consistent UIs), Apple only allows you to use their AirPlay button/UI for tapping into this feature. You can, however, put that button wherever you want:

airplayButton = [[MPVolumeView alloc] init];
airplayButton.frame = CGRectMake(myX, myY, 40, 40);
[airplayButton setShowsVolumeSlider:NO];
[customPlayerControls.view addSubview:airplayButton];

I just guessed on the width,height being 40,40 and I'm sure it's not correct, but once I got the button in place it didn't matter.

like image 149
devdavid Avatar answered Nov 09 '22 03:11

devdavid


for (UIButton *button in volumeView.subviews) {
if ([button isKindOfClass:[UIButton class]]) {
    [button setImage:[UIImage imageNamed:@"custom-route-button.png"] forState:UIControlStateNormal];
    [button sizeToFit];
}}

I think this will help you.

like image 30
user755278 Avatar answered Nov 09 '22 04:11

user755278


The MPVolumeView has an attribute to hide the volume slider and to show the Route button. So there is no need to traverse the views hiding things.

MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:myContainerView.bounds] autorelease];
volumeView.showsVolumeSlider = NO;
volumeView.showsRouteButton = YES;
[myContainerView addSubview:volumeView];

The placement of the AirPlay (Route) button may not be what you expect so you may have to play the frame of the container view a bit to get it where you want it.

like image 26
Skabber Avatar answered Nov 09 '22 03:11

Skabber