Skip to content

Commit 4c26301

Browse files
committed
Add option to show/hide play button
1 parent 6f1a274 commit 4c26301

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

SwiftRadio/Main.storyboard

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="kdl-ej-Zz5">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="kdl-ej-Zz5">
33
<device id="retina5_5" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
77
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
99
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
1010
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1111
</dependencies>
@@ -522,7 +522,7 @@
522522
<navigationItem key="navigationItem" title="SubPop Records" id="M1Z-0o-hNV" userLabel="Station Title"/>
523523
<nil key="simulatedBottomBarMetrics"/>
524524
<connections>
525-
<outlet property="AirPlayUIView" destination="djB-ds-tW4" id="JAG-TE-Fcg"/>
525+
<outlet property="airPlayView" destination="djB-ds-tW4" id="JAG-TE-Fcg"/>
526526
<outlet property="albumHeightConstraint" destination="hCD-tK-vVP" id="VlU-n5-VPe"/>
527527
<outlet property="albumImageView" destination="obn-8m-awZ" id="13r-WO-VAs"/>
528528
<outlet property="artistLabel" destination="v3l-q6-g0h" id="s0B-6Y-MWu"/>
@@ -805,7 +805,7 @@
805805
<image name="btn-previous" width="44" height="44"/>
806806
<image name="btn-stop" width="44" height="44"/>
807807
<image name="icon-hamburger" width="22" height="16"/>
808-
<image name="logo" width="180" height="71"/>
808+
<image name="logo" width="60" height="23.666666030883789"/>
809809
<image name="share" width="32" height="32"/>
810810
<image name="stationImage" width="120" height="75"/>
811811
<image name="swift-radio-black" width="180" height="70"/>

SwiftRadio/NowPlayingViewController.swift

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

SwiftRadio/SwiftRadio-Settings.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,10 @@ let searchable = false
4242

4343
// Set this to "false" to show the next/previous player buttons
4444
let hideNextPreviousButtons = true
45+
46+
//**************************************
47+
// AirPlay BUTTON
48+
//**************************************
49+
50+
// Set this to "true" to hide the AirPlay button
51+
let hideAirPlayButton = false

0 commit comments

Comments
 (0)