Audio Route Button - AirPlay

1.9k views Asked by At

I am currently playing audio through AudioQueues. I would like to allow users to connect to Airplay devices.

If I create an MPVolumeView and use the 'showsRouteButton' to display the route button I can successfully connect.

Is there a way to change the Audio Route to Airplay without using the MPVolumeView? Or a simpler Apple view that is just the route button?

3

There are 3 answers

1
Saurabh On BEST ANSWER

I don't think there is any other way to show the airplay route button (at least in current SDK iOS 5.1).. If you want to show AirPlay options you have to use MPVolumeView..

0
Tim Kozak On

1 hide MPVolumeView and make it as global var

CGRect frame = CGRectZero;
frame.origin.y = 0;
frame.origin.x = 410; // out of the screen
_volumeView = [[MPVolumeView alloc] initWithFrame:frame];
[_volumeView setShowsVolumeSlider:NO];
[_volumeView setShowsRouteButton:YES];
[self.view addSubview:_volumeView];

2 simulate button tapes

- (IBAction)handleAirPlay:(id)sender {
        for (UIButton *button in _volumeView.subviews)
        {
            if ([button isKindOfClass:[UIButton class]])
            {
                [button sendActionsForControlEvents:UIControlEventTouchUpInside];
            }
        }
}
0
batsansierra On

Since iOS 11 you can use AVRoutePicker :

import AVKit 

let rpv = AVRoutePickerView()
view.addSubview(rpv)