I use MPVolumeView
and UISlider
to control my device audio and below is my code:
extension MPVolumeView {
var volumeSlider: UISlider {
self.showsRouteButton = false
self.showsVolumeSlider = true
var slider = UISlider()
for subview in self.subviews {
if subview.isKind(of: UISlider.self){
slider = subview as! UISlider
slider.isContinuous = false
slider.minimumTrackTintColor = UIColor.outlineStrokeColor
slider.setThumbImage(#imageLiteral(resourceName: "volume"), for: .normal)
slider.maximumTrackTintColor = UIColor.lightGray
(subview as! UISlider).value = AVAudioSession.sharedInstance().outputVolume
return slider
}
}
return slider
}
}
let mpVolumeView: MPVolumeView = {
let view = MPVolumeView()
return view
}()
override func viewDidLoad() {
_ = mpVolumeView.volumeSlider
view.addSubview(mpVolumeView)
}
Everything works great but everytime when I open my app, the volume HUD appears and fades away after a few seconds. It won't show up again after that but I wish there would be an option to hide it all the time. I have tried to set MPVolumeView's frame to .zero but it still doesn't work. Is there a way that I can do so?