Before, I was setting sound volume programmatically using this approach:
MPVolumeView *volumeView = [[MPVolumeView alloc] init];
UISlider *volumeViewSlider =
I had to have a MPVolumeView as subview to a view in the hierarchy for the hud not to show up on iOS 12. It needs to be slightly visible:
let volume = MPVolumeView(frame: .zero)
volume.setVolumeThumbImage(UIImage(), for: UIControl.State())
volume.isUserInteractionEnabled = false
volumelume.alpha = 0.0001
volume.showsRouteButton = false
view.addSubview(volume)
When setting the volume I get the slider from MPVolumeView as with previous posters and set the value:
func setVolumeLevel(_ volumeLevel: Float) {
guard let slider = volume.subviews.compactMap({ $0 as? UISlider }).first else {
return
}
slider.value = volumeLevel
}