@@ -41,7 +41,7 @@ class NowPlayingViewController: UIViewController {
4141 @IBOutlet weak var volumeParentView : UIView !
4242 @IBOutlet weak var previousButton : UIButton !
4343 @IBOutlet weak var nextButton : UIButton !
44- @IBOutlet weak var AirPlayUIView : UIView !
44+ @IBOutlet weak var airPlayView : UIView !
4545
4646 // MARK: - Properties
4747
@@ -81,19 +81,8 @@ class NowPlayingViewController: UIViewController {
8181 // Setup volumeSlider
8282 setupVolumeSlider ( )
8383
84- // Setup AirPlay View if on ios 11.0
85- if #available( iOS 11 . 0 , * ) {
86- let AirPlayButton = AVRoutePickerView ( frame: AirPlayUIView . bounds)
87- AirPlayButton . activeTintColor = globalTintColor
88- AirPlayButton . tintColor = . gray
89- AirPlayUIView . backgroundColor = UIColor . clear
90- AirPlayUIView . addSubview ( AirPlayButton)
91- } else {
92- let AirPlayButton = MPVolumeView ( frame: AirPlayUIView . bounds)
93- AirPlayButton . showsVolumeSlider = false
94- AirPlayUIView . backgroundColor = UIColor . clear
95- AirPlayUIView . addSubview ( AirPlayButton)
96- }
84+ // Setup AirPlayButton
85+ setupAirPlayButton ( )
9786
9887 // Hide / Show Next/Previous buttons
9988 previousButton. isHidden = hideNextPreviousButtons
@@ -124,6 +113,26 @@ class NowPlayingViewController: UIViewController {
124113 mpVolumeSlider. setThumbImage ( #imageLiteral( resourceName: " slider-ball " ) , for: . normal)
125114 }
126115
116+ func setupAirPlayButton( ) {
117+ guard !hideAirPlayButton else {
118+ airPlayView. isHidden = true
119+ return
120+ }
121+
122+ if #available( iOS 11 . 0 , * ) {
123+ let airPlayButton = AVRoutePickerView ( frame: airPlayView. bounds)
124+ airPlayButton. activeTintColor = globalTintColor
125+ airPlayButton. tintColor = . gray
126+ airPlayView. backgroundColor = . clear
127+ airPlayView. addSubview ( airPlayButton)
128+ } else {
129+ let airPlayButton = MPVolumeView ( frame: airPlayView. bounds)
130+ airPlayButton. showsVolumeSlider = false
131+ airPlayView. backgroundColor = . clear
132+ airPlayView. addSubview ( airPlayButton)
133+ }
134+ }
135+
127136 func stationDidChange( ) {
128137 radioPlayer. radioURL = URL ( string: currentStation. streamURL)
129138 albumImageView. image = currentTrack. artworkImage
0 commit comments