0

Airplay button is showing on the UIToolbar but when clicking it nothing is happening. It should open up airplay picker. but it is not.

    UIButton *volumeView = [UIButton buttonWithType:UIButtonTypeCustom];
    [volumeView addTarget:self action:@selector(MPVolumeView:) forControlEvents:UIControlEventTouchUpInside];

    volumeView.frame = CGRectMake(0, 0, 40, 40);

    UIImage *icon = [UIImage imageNamed:@"airplay-1.png"];

    [volumeView setImage:icon forState:UIControlStateNormal];


    UIBarButtonItem *volumeview = [[UIBarButtonItem alloc] initWithCustomView:volumeView];


-(void)MPVolumeView:(id)sender
  {
  MPVolumeView *volumeView = [[MPVolumeView alloc] init];
  [volumeView setShowsVolumeSlider:NO];
  [volumeView setShowsRouteButton:YES];
 // [volumeView sizeToFit];
  [volumeView release];
  }

I dont see anything wrong with the code but still wondering why it is not opening up airplay picker for scrollview images in the app. Actually in this case airplay is for uiimages. can we airplay UIImages.

Thanks for help.

user1452248
  • 767
  • 2
  • 11
  • 28

1 Answers1

2

Creating an instance of MPVolumeView doesn't actually open the Airplay picker, it creates the button which upon press, opens the picker.

Try something like this:

MPVolumeView *myVolumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(0, 0, 45, 33)];
myVolumeView.showsVolumeSlider = NO;
myVolumeView.showsRouteButton = YES;

UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myVolumeView];
Kevin Renskers
  • 5,156
  • 4
  • 47
  • 95