I'm digging all over the web trying to find some clue to achieve this but no success.
I'm trying to show up the user a popup like Waze does to allow the user to select the audio output device, volume etc.
It seems to be some API as it shows exactly as sound widget on iOS11.
Any help appreciated.
For those struggling on it like me, here a potential solution.
I don't know if there is a better solution. If so, please share.
I needed a custom button to make exactly the same MPVolumeView Route Button. So I could achieve the same effect and functionality masking the original button.
import UIKit
import MediaPlayer
class SelectAudioDeviceViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let avView = myView(frame: CGRect(x: 0, y: 0, width: 150, height: 50))
let button = UIButton(frame: CGRect(x: 50, y: 150, width: 150, height: 50))
avView.showsRouteButton = true
avView.showsVolumeSlider = false
avView.setRouteButtonImage(nil, for: .normal)
button.backgroundColor = UIColor.gray
button.setTitle("BLABLA", for: .normal)
button.addSubview(avView)
self.view.addSubview(button)
}
}
class myView: MPVolumeView {
override func routeButtonRect(forBounds bounds: CGRect) -> CGRect {
let newBounds = CGRect(x: 0, y: 0, width: 150, height: 50)
return newBounds
}
}
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With