added cover view

master
Bill 2 years ago
parent 87c5ff74ac
commit 6c6af5a7e6

@ -35,11 +35,15 @@ class ListViewModel: ObservableObject {
struct ContentView: View {
@ObservedObject var music = ListViewModel()
@State var pushState = false
@State var geo :CGSize = .zero
@State var _curr_sel_music : IDStr = IDStr()
var body: some View {
GeometryReader { geometry in
NavigationView(){
List() {
ForEach(music.music) { m in
VStack(){
Button(m.s, action: {
let idx = music.music.firstIndex { s in
s.s == m.s
@ -57,13 +61,22 @@ struct ContentView: View {
m.m!.seek(to: .zero)
}
}
pushState = true
_curr_sel_music = m
}).ignoresSafeArea(.all).cornerRadius(.zero).padding(.zero).frame(maxHeight: CGFloat(50)).foregroundColor(.white)
NavigationLink(destination: PlaybackView(parent:self, music: _curr_sel_music), isActive: $pushState) {
EmptyView()
}
}
}
}
}.onAppear {
geo = geometry.size
}
}
}
var player : AVQueuePlayer? = nil
init() {
@ -127,6 +140,7 @@ struct ContentView: View {
let file_url = URL(filePath: dir + "/Documents/" + filename)
let asset = AVAsset(url: file_url)
let idstr = IDStr()
let geo = self.geo
asset.loadMetadata(for: .iTunesMetadata) {
items, b in
for i in items! {
@ -134,6 +148,9 @@ struct ContentView: View {
Task{
let imageData = try await i.load(.dataValue)
idstr.art = Image(uiImage: UIImage(data: imageData!)!)
if (idstr.art != nil) {
idstr.art!.resizable().scaledToFill().frame(width: geo.width, height: geo.height)
}
}
}
}

@ -8,12 +8,20 @@
import SwiftUI
struct PlaybackView: View {
var placeholder: Image? = nil
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
placeholder == nil ?
nil : placeholder!.resizable().scaledToFill()
}
init() {}
init(parent:ContentView) {
init() {}
init(parent:ContentView, music: IDStr) {
if music.art != nil {
self.placeholder = music.art!
}
}
}

Loading…
Cancel
Save