Search code examples
c#formsxamarinvolumempvolumeview

How to remove volume HUD on Xamarin Forms?


I have made a customrenderer to render a MPVolumeView inside of a xamarin.forms app. Whenever I adjust the volume, I get this big system HUD on screen that is blocking the content on screen. Looks something like this: enter image description here

How do I remove this? This is my custom renderer:

public class AudioOutputViewRenderer : ViewRenderer<AudioOutputView, UIView>
{
    MPVolumeView view;

    protected override void OnElementChanged(ElementChangedEventArgs<AudioOutputView> e)
    {
        base.OnElementChanged(e);

        TintColor = UIColor.FromRGB(54, 66, 94);

        if (Control == null)
        {
            view = new MPVolumeView()
            {
                ShowsRouteButton = false,
                ShowsVolumeSlider = true

            };

            SetNativeControl(view);
        }
    }
}

Solution

  • I didnt understand perpose of the AudioOutputViewRenderer

    But to hide the MPVolumeView you need next:

    in your IosProject -> AppDelegate -> method FinishedLaunching add next code

            var volumeView = new MPVolumeView(new CGRect(-1000,0,0,0));// -1000 will hide your view  from user 
            volumeView.ClipsToBounds = true;
            var slider = volumeView.Subviews.First(x => x is UISlider) as UISlider;
            UIApplication.SharedApplication.KeyWindow.RootViewController.View.AddSubview(volumeView);
    

    After you can use var slider to change volume like this

            slider.Value = [your vlm];