Yandex Music client for Apple TV
tvOS 17+ SwiftUI client for the unofficial Yandex Music API: rotor stations with feedback, library, search, artist and album pages, synced lyrics, and system Now Playing integration.
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
import SwiftUI
|
||||
|
||||
struct AlbumView: View {
|
||||
let album: Album
|
||||
@EnvironmentObject private var player: PlayerController
|
||||
|
||||
@State private var full: Album?
|
||||
@State private var tracks: [Track] = []
|
||||
@State private var isLoading = true
|
||||
|
||||
private var resolved: Album { full ?? album }
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 40) {
|
||||
header
|
||||
|
||||
if isLoading {
|
||||
LoadingState(text: "Загружаем альбом…").frame(height: 300)
|
||||
} else {
|
||||
LazyVStack(spacing: 6) {
|
||||
ForEach(Array(tracks.enumerated()), id: \.offset) { pair in
|
||||
HStack(spacing: 0) {
|
||||
Text("\(pair.offset + 1)")
|
||||
.font(.headline.monospacedDigit())
|
||||
.foregroundStyle(.white.opacity(0.35))
|
||||
.frame(width: 60, alignment: .trailing)
|
||||
|
||||
TrackRow(
|
||||
track: pair.element,
|
||||
isCurrent: player.current?.trackID == pair.element.trackID
|
||||
) {
|
||||
play(from: pair.offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.top, 120)
|
||||
.padding(.bottom, 60)
|
||||
}
|
||||
.background(backdrop)
|
||||
.task { await load() }
|
||||
}
|
||||
|
||||
private var backdrop: some View {
|
||||
BlurredBackdrop(url: resolved.coverURL(size: 200))
|
||||
}
|
||||
|
||||
private var header: some View {
|
||||
HStack(alignment: .top, spacing: 50) {
|
||||
CoverImage(url: resolved.coverURL(size: 400), corner: 16)
|
||||
.frame(width: 340, height: 340)
|
||||
|
||||
VStack(alignment: .leading, spacing: 14) {
|
||||
Text(resolved.displayTitle)
|
||||
.font(.system(size: 52, weight: .bold))
|
||||
.lineLimit(3)
|
||||
|
||||
if let artist = resolved.artists?.first {
|
||||
NavigationLink(value: MusicRoute.artist(artist)) {
|
||||
Text(resolved.artistNames)
|
||||
.font(.title3)
|
||||
.foregroundStyle(Color.ymAccent)
|
||||
}
|
||||
.buttonStyle(RowButtonStyle())
|
||||
.fixedSize()
|
||||
} else {
|
||||
Text(resolved.artistNames)
|
||||
.font(.title3)
|
||||
.foregroundStyle(.white.opacity(0.6))
|
||||
}
|
||||
|
||||
if !resolved.subtitleLine.isEmpty {
|
||||
Text(resolved.subtitleLine)
|
||||
.font(.body)
|
||||
.foregroundStyle(.white.opacity(0.55))
|
||||
}
|
||||
|
||||
HStack(spacing: 20) {
|
||||
Button { play(from: 0) } label: {
|
||||
Label("Слушать", systemImage: "play.fill")
|
||||
}
|
||||
.disabled(tracks.isEmpty)
|
||||
|
||||
Button {
|
||||
player.play(
|
||||
tracks: tracks.shuffled(),
|
||||
startAt: 0,
|
||||
source: .collection(resolved.displayTitle)
|
||||
)
|
||||
} label: {
|
||||
Label("Вперемешку", systemImage: "shuffle")
|
||||
}
|
||||
.disabled(tracks.isEmpty)
|
||||
}
|
||||
.padding(.top, 10)
|
||||
|
||||
if let description = resolved.shortDescription, !description.isEmpty {
|
||||
Text(description)
|
||||
.font(.callout)
|
||||
.foregroundStyle(.white.opacity(0.6))
|
||||
.frame(maxWidth: 900, alignment: .leading)
|
||||
.padding(.top, 8)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
}
|
||||
|
||||
private func play(from index: Int) {
|
||||
guard !tracks.isEmpty else { return }
|
||||
player.play(tracks: tracks, startAt: index, source: .collection(resolved.displayTitle))
|
||||
}
|
||||
|
||||
private func load() async {
|
||||
isLoading = true
|
||||
defer { isLoading = false }
|
||||
do {
|
||||
let loaded = try await YMClient.shared.album(albumID: album.id.value)
|
||||
full = loaded
|
||||
tracks = (loaded.volumes ?? []).flatMap { $0 }
|
||||
} catch {
|
||||
log.error("\(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user