-
Notifications
You must be signed in to change notification settings - Fork 0
/
StationListView.swift
42 lines (37 loc) · 1.12 KB
/
StationListView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import SwiftUI
import AVKit
struct StationListView: View {
@ObservedObject var pandoraAPI: PandoraAPI
var body: some View {
VStack {
List(pandoraAPI.stations) { station in
Button(action: {
pandoraAPI.playStation(station)
}) {
Text(station.stationName)
}
}
if let audioPlayer = pandoraAPI.audioPlayer {
AudioPlayerView(audioPlayer: audioPlayer)
}
}
}
}
struct AudioPlayerView: View {
@ObservedObject var audioPlayer: AVPlayer
var body: some View {
VStack {
Text(audioPlayer.currentItem?.asset.metadata.first?.value.value(forKey: "title") as? String ?? "Unknown Title")
.font(.title)
HStack {
Button(action: audioPlayer.pause) {
Image(systemName: "pause.fill")
}
Button(action: audioPlayer.play) {
Image(systemName: "play.fill")
}
}
}
.padding()
}
}