Airplay is a great feature in iOS. So I needed a UI for selection. Also a Slider for the volume. There is an open source project which has a default GUI implementation. But there are problems:
- Some not reproducible NullException (thats the reason I cannot make an issue for that
- Slider and Airplay Button are fixed in UI
So I had a look into it. We have to use MPVolumeView for the volume and AVRoutePickerView (iOS11+) for selection of the external sources.
Here es an example how it can be implemented in the GUI (Cuterdio). We have a separate slider and a separate button for Airplay:
The example let you pass a Slider which can feedback the volume change.
public class AudioManagerIos : IAudioManager { public Slider Slider { get; set; } private UISlider _slider; public AudioManagerIos() { MPVolumeView mpVolumeView = new MPVolumeView(); _slider = mpVolumeView.Subviews.OfType<UISlider>().FirstOrDefault(); if (_slider != null) { _slider.ValueChanged += _slider_ValueChanged; } } private void _slider_ValueChanged(object sender, EventArgs e) { Volume = _slider.Value; } public void ShowExternalDevices() { var routePickerView = new AVRoutePickerView(); var button = routePickerView.Subviews.OfType<UIButton>().FirstOrDefault(); button?.SendActionForControlEvents(UIControlEvent.TouchUpInside); routePickerView.Dispose(); } public float Volume { get { return _slider.Value; } set { _slider.Value = value; if (Slider != null) { Slider.Value = _slider.Value; } } } }