feat: receive ordered stream playback queues
This commit is contained in:
@@ -4,11 +4,14 @@ struct PlaybackQueue {
|
||||
struct Item: Identifiable {
|
||||
let id = UUID()
|
||||
let url: URL
|
||||
var label: String? = nil
|
||||
var displayName: String { label ?? url.lastPathComponent }
|
||||
}
|
||||
|
||||
private(set) var items: [Item] = []
|
||||
private(set) var currentID: UUID?
|
||||
var currentURL: URL? { items.first { $0.id == currentID }?.url }
|
||||
var currentItem: Item? { items.first { $0.id == currentID } }
|
||||
var currentURL: URL? { currentItem?.url }
|
||||
private var currentIndex: Int? { items.firstIndex { $0.id == currentID } }
|
||||
var canPrevious: Bool { currentIndex.map { $0 > 0 } ?? false }
|
||||
var canNext: Bool { currentIndex.map { $0 + 1 < items.count } ?? false }
|
||||
@@ -18,6 +21,17 @@ struct PlaybackQueue {
|
||||
currentID = items.first?.id
|
||||
}
|
||||
|
||||
// Unlike file batches, stream entries already have an intentional playback order.
|
||||
mutating func replaceStreams(_ entries: [(url: URL, label: String)]) {
|
||||
items = entries.map { Item(url: $0.url, label: $0.label) }
|
||||
currentID = items.first?.id
|
||||
}
|
||||
|
||||
mutating func updateCurrentLabel(_ label: String) {
|
||||
guard let index = currentIndex else { return }
|
||||
items[index].label = label
|
||||
}
|
||||
|
||||
mutating func append(_ urls: [URL]) {
|
||||
items.append(contentsOf: sortedFiles(urls).map { Item(url: $0) })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user