Jacob Cavin
Jacob Cavin

Reputation: 2319

Adding AirPlay To AVAudioPlayer (Swift)

I'm making a music app with an AVAudioPlayer. I would like the user to be able to open the AirPlay picker view...

AirPlay Picker View

...by tapping a UIBarButtonItem in a UIToolBar to stream the music playing from my app. How would I do this?

Upvotes: 0

Views: 700

Answers (1)

Gary Makin
Gary Makin

Reputation: 3169

Start with an MPVolumeView without the volume slider:

MPVolumeView* myVolumeView = [[MPVolumeView alloc] initWithFrame: CGRectMake(...)];
myVolumeView. showsVolumeSlider = NO;

See Add MPVolumeView to bottom toolbar for how to add an MPVolumeView to a UIBarButtonItem, i.e.:

UIBarButtonItem* b = [[UIBarButtonItem alloc] initWithCustomView: myVolumeView];

Swift 4

var myVolumeView = MPVolumeView(frame: CGRect(x: x, y: y, width: width, height: height))
myVolumeView.showsVolumeSlider = false
var airplayButton = UIBarButtonItem(customView: myVolumeView)

Upvotes: 1

Related Questions