I want to implement an Airplay button that shows the Bluetooth, iPhone option like in the iPhone music app we click on Airplay. I did some of the code but I am facing some issues.
- As I implement, MPVolumeView works fine but unable to change the button colour. I checked with tint colour but not working
- Added code of AVRoutePickerView it's not working It does not trigger so It not display that AirPlay Popup view
- I want to show this Airplay Popup View when clicking on UIButton but I can't find any solution regards this so I take UIView for it.
There are some links SO that work for some of the points but not for the whole thing
https://developer.jwplayer.com/jwplayer/docs/ios-add-an-airplay-button-to-an-app
iOS - How can I display an 'AirPlay' popup menu in Swift?
Please check the below Screenshot for more information.
Please check the code
import UIKit
import MediaPlayer
import AVKit
class TempDemoViewController: UIViewController {
@IBOutlet weak var airPlayView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
setupAirPlayButton()
}
func setupAirPlayButton() {
var buttonView: UIView = UIView()
let buttonFrame = CGRect(x: 0, y: 0, width: 50, height: 50)
if #available(iOS 11, *) {
let routerPickerView = AVRoutePickerView(frame: buttonFrame)
buttonView.addSubview(routerPickerView)
routerPickerView.tintColor = UIColor(named: "PrimaryColor")
routerPickerView.activeTintColor = .white
routerPickerView.prioritizesVideoDevices = true
}else{
let airplayButton = MPVolumeView(frame: buttonFrame)
airplayButton.showsVolumeSlider = false
buttonView = airplayButton
}
airPlayView.addSubview(buttonView)
}
}