How to hide route button `showsRouteButton = false` in `MPVolumeView` without deprecation warning?

MPVolumeView's showsRouteButton was deprecated (https://developer.apple.com/documentation/mediaplayer/mpvolumeview/showsroutebutton?language=objc).

It's not clear how can we now hide this button without deprecation warning. The documentation is lacking.

Please advise.

Thank you!

Thanks so much for the post.

My answer will not be to find ways to suppress of the deprecation warning. Spoiler alert.

This warning indicates that the API including your method will cease to function, and the documentation advises utilizing the AVRoutePickerView as an alternative. Consequently, I would recommend transitioning entirely to the AVRoutePickerView.

As that class you are using including the method showsRouteButton will stop working in the future releases.

Please let me know if I can help you moving to the AVRoutePickerView as the documentation shows.

Albert Pascual
  Worldwide Developer Relations.

Thank you for a quick reply.

We are using non-deprecated MPVolumeView (https://developer.apple.com/documentation/mediaplayer/mpvolumeview) to control system audio output volume.

// volumeView is `MPVolumeView`
volumeView.showsRouteButton = false
volumeView.backgroundColor = .clear
addSubview(volumeView)
volumeView.snp.makeConstraints { make in
  make.top.greaterThanOrEqualTo(self)
  make.bottom.lessThanOrEqualTo(self)
  make.centerY.equalToSuperview()
   make.leading.equalTo(volumeMuteImageView.snp.trailing).offset(6). make.trailing.equalTo(volumeHighImageView.snp.leading).offset(-15)
  make.height.equalTo(44)
        }

What should we do?

Thank you!

Like the documentation explains to control the audio for that control use AVRoutePickerView

Thanks Albert 
  Worldwide Developer Relations.

Sorry, but for which control? Do you mean for the slider?

AVRoutePickerView
A view that presents a list of nearby media receivers.

My question is about MPVolumeView .

Sorry, but how do I wire up AVRoutePickerView with MPVolumeView, in the documentation there's no example. That documentation also doesn't say anything about controlling system volume, It only says about handling media receivers.

Can you help me?

@DTS Engineer Hi, It's been 4 months, can you reply to my question? As I explained we use the MPVolumeView to control system audio volume. Your answer about using AVRoutePickerView doesn't apply to our use case. What should we do? Is there a way to control system volume via a different API and is not private? Thank you.

I didn't get alerted the first time.

Intentionally direct programmatic control of the system volume to prevent apps from overriding user intent MPVolumeView remains is the non-private way to provide a UI for system volume control.

While you must use MPVolumeView, you can customize its appearance so it doesn't look like the default system slider. Because MPVolumeView uses a UISlider under the hood.

Is your goal is simply to allow users to use the physical hardware buttons to change volume without the system Volume HUD appearing on screen? If you need strict programmatic control over audio levels without user interaction, you cannot change the system volume.

If you need to control the global system volume, you are strictly bound to MPVolumeView. Suppressing deprecation warnings per-line is unfortunately not supported by the compiler.

MPVolumeView

https://developer.apple.com/documentation/mediaplayer/mpvolumeview

showsRouteButton: https://developer.apple.com/documentation/mediaplayer/mpvolumeview/showsroutebutton

showsVolumeSlider: https://developer.apple.com/documentation/mediaplayer/mpvolumeview/showsvolumeslider

AVRoutePickerView

https://developer.apple.com/documentation/avkit/avroutepickerview

Albert  WWDR

How to hide route button `showsRouteButton = false` in `MPVolumeView` without deprecation warning?
 
 
Q