forked from HammerPot/Maple-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTracks.swift
More file actions
41 lines (39 loc) · 1.1 KB
/
Tracks.swift
File metadata and controls
41 lines (39 loc) · 1.1 KB
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
import SwiftUI
import AVFoundation
struct Tracks: View {
@State private var songs: [Song] = []
@State private var isLoading = true
var body: some View {
VStack {
if isLoading {
ProgressView("Loading tracks...")
} else if songs.isEmpty {
Text("No music files found")
.font(.headline)
.foregroundColor(.gray)
.padding()
} else {
List {
ForEach(songs.sorted(by: { $0.title < $1.title })) { song in
NavigationLink(destination: AudioPlayerView(song: song, allSongs: songs.sorted(by: { $0.title < $1.title }))) {
Text(song.title)
}
}
}
}
}
.navigationTitle("Tracks")
.onAppear {
Task{
loadSongsJ()
}
}
}
private func loadSongsJ(){
isLoading = true
Task {
songs = await loadSongsFromJson()
}
isLoading = false
}
}