Volume change with MPVolumeView not working in iOS 11.4

I have a music app and have been using MPVolumeView to change volume of media player in my application. Volume changes happens at runtime when user asked our server to change the volume so the volume value varies based on the request. I am using the below code snippet to make it happen.


let volumeSlider = (MPVolumeView().subviews.filter { NSStringFromClass($0.classForCoder) == "MPVolumeSlider" }.first as! UISlider)

volumeSlider.setValue(value, animated: false)


The above code was working fine till iOS 11.3 irrespective of whether the device is connected to external accessory such as BT device or not.



But it is not working in iOS 11.4 when BT device is connected to iPhone.

As per analysis, i got the below logs in the terminal whenever the above code executed.



<<<< AVOutputDeviceDiscoverySession (FigRouteDiscoverer) >>>> -[AVFigRouteDiscovererOutputDeviceDiscoverySessionImpl outputDeviceDiscoverySessionDidChangeDiscoveryMode:]: Setting device discovery mode to DiscoveryMode_None



I also noticed that MPVolumeSliderView.value is getting set with the new value in the logs but the effect of the sound volume doesn't changed.


Please let me know what i am missing if i want to change the volume while BT device is connected.

Replies

Same problem, using IOS 11.4.1 and also IOS 12 beta

You are attempting to modify the private view hierarchy of MPVolumeView, which is not explicitly allowed by the documentation. Thus, you cannot expect this to work. You should use public APIs instead.

erratic/unpredictable behavior in iOS 17.3 while using this approach as well. obviously not surprised given that it's not in the public API.