6

4.3 finally :) I am searching right now how to add air play button to custom view. I have MPMoviePlayer that load movie. I disabled standard controls and added overlay view with my custom play, pause, stop, volume buttons. If anybody know how to add button that will be air play please share knowledge? I cant't find what notification to send, what to listen...:(

1110
  • 7,829
  • 55
  • 176
  • 334

3 Answers3

40

If you want just the AirPlay button without the volume slider follow the instructions in Jilouc's answer and then set the following properties on the myVolumeView:

[myVolumeView setShowsVolumeSlider:NO];
[myVolumeView setShowsRouteButton:YES];

That will hide the volume slider but keep the route button.

Hivebrain
  • 784
  • 1
  • 8
  • 11
15

EDIT It seems I've been misguided in my previous answer because the device was not running the released version iOS 4.3.

There is a way to provide the AirPlay button on a custom interface.
Use a MPVolumeView and add it to your view hierarchy

MPVolumeView *myVolumeView =
[[MPVolumeView alloc] initWithFrame: overlayView.bounds];
[overlayView addSubview: myVolumeView];
[myVolumeView release];

The MPVolumeView provides the volume slider and the route button (see image below). But I don't think it's possible to only display the button.

MPVolumeView at the bottom

Jilouc
  • 12,684
  • 4
  • 46
  • 43
  • I don't have AppleTV with me now but I will test it as soon as I can. I can't wait to see this feature :) There is explanation also here http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPVolumeView_Class/Reference/Reference.html about VolumeView. Thanks – 1110 Mar 17 '11 at 07:21
  • it doesn't work for me. the button is shown, but doesn't do anything when I click AppleTV button. Any ideas? – Tibidabo Jul 08 '11 at 14:46
  • Remember to add 'MediaPlayer.framework' in Project's Build Phases under 'Link Binary With Libraries' section. Otherwise you will see just blank view. – Kashif Hisam Sep 29 '11 at 10:37
  • 4
    Sorry, I know this is an old question. But it is possible to just show the button without the slider by using - [MPVolumeView setShowsVolumeSlider:NO]; – Giz Jun 05 '13 at 14:23
  • if you don't have an AppleTV, you should be able to use apps like AirServer on a mac? – Ondrej Rafaj Jun 11 '13 at 16:49
2

In the Documentation Apple also includes a snippet for that:

MPVolumeView *volumeView = [ [MPVolumeView alloc] init] ;
[volumeView setShowsVolumeSlider:NO];
[volumeView sizeToFit];
[view addSubview:volumeView];
lukaswelte
  • 2,951
  • 1
  • 23
  • 45