Skip to content

Commit fca0930

Browse files
authored
Fixes remote audio source network issues (#35)
1 parent 2f08ea4 commit fca0930

20 files changed

Lines changed: 87 additions & 67 deletions

AudioExample/AudioExample/AppCoordinator.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import UIKit
1010

1111
final class AppCoordinator {
12-
1312
enum Route {
1413
case equalizer
1514
}
@@ -44,8 +43,8 @@ final class AppCoordinator {
4443

4544
private func routeTo(_ route: AppCoordinator.Route) {
4645
switch route {
47-
case .equalizer:
48-
showEqualizerControls()
46+
case .equalizer:
47+
showEqualizerControls()
4948
}
5049
}
5150

AudioExample/AudioExample/Controllers/EqualizerViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import UIKit
1010

1111
class EqualizerViewController: UIViewController {
12-
1312
private lazy var enableTextLabel = UILabel()
1413
private lazy var enableButton = UISwitch()
1514

@@ -22,7 +21,8 @@ class EqualizerViewController: UIViewController {
2221
super.init(nibName: nil, bundle: nil)
2322
}
2423

25-
required init?(coder: NSCoder) {
24+
@available(*, unavailable)
25+
required init?(coder _: NSCoder) {
2626
fatalError("init(coder:) has not been implemented")
2727
}
2828

@@ -69,7 +69,7 @@ class EqualizerViewController: UIViewController {
6969
stackView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
7070
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
7171
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
72-
stackView.heightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.heightAnchor, multiplier: 0.8)
72+
stackView.heightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.heightAnchor, multiplier: 0.8),
7373
]
7474
)
7575
}
@@ -86,7 +86,7 @@ class EqualizerViewController: UIViewController {
8686

8787
private func buildSliders() -> [UIView] {
8888
var sliders = [UIView]()
89-
for index in 0..<viewModel.numberOfBands() {
89+
for index in 0 ..< viewModel.numberOfBands() {
9090
guard let item = viewModel.band(at: index) else { continue }
9191
let slider = buildSlider(item: item, index: index)
9292
sliders.append(slider)

AudioExample/AudioExample/Controllers/EqualizerViewModel.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ struct EQBand {
1616
}
1717

1818
final class EqualzerViewModel {
19-
2019
private var bands: [EQBand] = []
2120

2221
private let equalizerService: EqualizerService
@@ -31,7 +30,7 @@ final class EqualzerViewModel {
3130
bands = equalizerService.bands.map { item in
3231
var measurement = item.frequency
3332
var frequency = String(Int(measurement))
34-
if item.frequency >= 1_000 {
33+
if item.frequency >= 1000 {
3534
measurement = item.frequency / 1000
3635
frequency = "\(String(Int(measurement)))K"
3736
}

AudioExample/AudioExample/Controllers/PlayerViewController.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class PlayerViewController: UIViewController {
5151
style: .plain,
5252
target: self,
5353
action: #selector(showEqualizer))
54-
54+
5555
tableView.translatesAutoresizingMaskIntoConstraints = false
5656
tableView.delegate = self
5757
tableView.dataSource = self
@@ -92,20 +92,21 @@ class PlayerViewController: UIViewController {
9292

9393
@objc private func addNowPlaylistItem() {
9494
let controller = UIAlertController(title: "Add new item", message: "", preferredStyle: .alert)
95-
controller.addTextField { (textField) in
95+
controller.addTextField { textField in
9696
textField.placeholder = "Insert url here"
9797
}
98-
let saveAction = UIAlertAction(title: "Save", style: .default) { [viewModel] action in
98+
let saveAction = UIAlertAction(title: "Save", style: .default) { [viewModel] _ in
9999
if let textfield = controller.textFields?.first,
100-
let text = textfield.text {
100+
let text = textfield.text
101+
{
101102
viewModel.add(urlString: text)
102103
}
103104
}
104105
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
105106

106107
controller.addAction(saveAction)
107108
controller.addAction(cancelAction)
108-
self.present(controller, animated: true, completion: nil)
109+
present(controller, animated: true, completion: nil)
109110
}
110111
}
111112

@@ -149,14 +150,13 @@ extension PlayerViewController: UITableViewDelegate {
149150
}
150151
}
151152

152-
153153
final class PlaylistTableViewCell: UITableViewCell {
154-
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
154+
override init(style _: UITableViewCell.CellStyle, reuseIdentifier: String?) {
155155
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
156156
}
157157

158158
@available(*, unavailable)
159-
required init?(coder: NSCoder) {
159+
required init?(coder _: NSCoder) {
160160
fatalError("init(coder:) has not been implemented")
161161
}
162162
}

AudioExample/AudioExample/Controllers/PlayerViewModel.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ final class PlayerViewModel {
1818
private let playerService: AudioPlayerService
1919
private let playlistItemsService: PlaylistItemsService
2020

21-
private let routeTo: ((AppCoordinator.Route) -> Void)
21+
private let routeTo: (AppCoordinator.Route) -> Void
2222
private var currentPlayingItemIndex: Int?
2323

2424
var reloadContent: ((ReloadAction) -> Void)?
2525

2626
init(playlistItemsService: PlaylistItemsService,
2727
playerService: AudioPlayerService,
28-
routeTo: @escaping (AppCoordinator.Route) -> Void) {
28+
routeTo: @escaping (AppCoordinator.Route) -> Void)
29+
{
2930
self.playlistItemsService = playlistItemsService
3031
self.playerService = playerService
3132
self.routeTo = routeTo

AudioExample/AudioExample/Services/EqualizerService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import AVFoundation
1010

1111
final class EqualizerService {
1212
private let playerService: AudioPlayerService
13-
private let _freqs = [32, 64, 128, 250, 500, 1_000, 2_000, 4_000, 8_000, 16_000]
13+
private let _freqs = [32, 64, 128, 250, 500, 1000, 2000, 4000, 8000, 16000]
1414
private let eqUnit: AVAudioUnitEQ
1515

1616
var bands: [AVAudioUnitEQFilterParameters] {
@@ -23,7 +23,7 @@ final class EqualizerService {
2323
self.playerService = playerService
2424

2525
eqUnit = AVAudioUnitEQ(numberOfBands: _freqs.count)
26-
for i in 0..<_freqs.count {
26+
for i in 0 ..< _freqs.count {
2727
eqUnit.bands[i].bypass = false
2828
eqUnit.bands[i].filterType = .parametric
2929
eqUnit.bands[i].frequency = Float(_freqs[i])

AudioExample/AudioExample/Services/NowPlayingCenter.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
import MediaPlayer
1010

1111
final class NowPlayingCenter {
12-
1312
private let infoCenter: MPNowPlayingInfoCenter
1413

15-
init(infoCenter: MPNowPlayingInfoCenter = .default()){
14+
init(infoCenter: MPNowPlayingInfoCenter = .default()) {
1615
self.infoCenter = infoCenter
1716
}
1817

AudioExample/AudioExample/Services/PlaylistItemsService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ final class PlaylistItemsService {
8080
func provideInitialPlaylistItems() -> [PlaylistItem] {
8181
let allCases = AudioContent.allCases
8282
let casesForQueueing: [AudioContent] = [.piano, .local, .khruangbin]
83-
let allItems = allCases.map { PlaylistItem.init(content: $0 , queues: false) }
84-
let casesForQueuingItems = casesForQueueing.map { PlaylistItem.init(content: $0 , queues: true) }
83+
let allItems = allCases.map { PlaylistItem(content: $0, queues: false) }
84+
let casesForQueuingItems = casesForQueueing.map { PlaylistItem(content: $0, queues: true) }
8585
return allItems + casesForQueuingItems
8686
}

AudioStreaming/Core/Extensions/AVAudioFormat+Convenience.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
import AVFoundation
77

8-
extension AVAudioFormat {
8+
public extension AVAudioFormat {
99
/// The underlying audio stream description.
1010
///
1111
/// This exposes the `pointee` value of the `UsafePointer<AudioStreamBasicDescription>`
12-
public var basicStreamDescription: AudioStreamBasicDescription {
12+
var basicStreamDescription: AudioStreamBasicDescription {
1313
return streamDescription.pointee
1414
}
1515
}

AudioStreaming/Core/Helpers/Retrier.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ final class Retrier {
3838

3939
/// Cancels retrying
4040
func cancel() {
41+
interval = .seconds(1)
4142
timeoutTimer.removeHandler()
4243
timeoutTimer.suspend()
4344
}

0 commit comments

Comments
 (0)