Persistence for queue, history and last played

This commit is contained in:
Arkadiusz Fal
2021-10-24 20:01:08 +02:00
parent 68b5abd122
commit 19bb4955a2
13 changed files with 330 additions and 118 deletions

View File

@@ -29,6 +29,10 @@ extension Defaults.Keys {
static let recentlyOpened = Key<[RecentItem]>("recentlyOpened", default: [])
static let queue = Key<[PlayerQueueItem]>("queue", default: [])
static let history = Key<[PlayerQueueItem]>("history", default: [])
static let lastPlayed = Key<PlayerQueueItem?>("lastPlayed")
static let trendingCategory = Key<TrendingCategory>("trendingCategory", default: .default)
static let trendingCountry = Key<Country>("trendingCountry", default: .us)
}

View File

@@ -111,6 +111,10 @@ struct ContentView: View {
playlists.accounts = accounts
search.accounts = accounts
subscriptions.accounts = accounts
if !accounts.current.isNil {
player.loadHistoryDetails()
}
}
func openWelcomeScreenIfAccountEmpty() {
@@ -135,6 +139,7 @@ struct ContentView: View {
accounts.api.video(id).load().onSuccess { response in
if let video: Video = response.typedContent() {
self.player.autoPlayItems = true
self.player.playNow(video, at: parser.time)
self.player.presentPlayer()
}

View File

@@ -24,7 +24,7 @@ struct PlaybackBar: View {
if !player.lastSkipped.isNil {
restoreLastSkippedSegmentButton
}
if player.currentVideo!.live {
if player.live {
Image(systemName: "dot.radiowaves.left.and.right")
} else if player.isLoadingAvailableStreams || player.isLoadingStream {
Image(systemName: "bolt.horizontal.fill")
@@ -78,7 +78,7 @@ struct PlaybackBar: View {
return "LIVE"
}
guard player.time != nil, player.time!.isValid else {
guard player.time != nil, player.time!.isValid, !player.currentVideo.isNil else {
return "loading..."
}

View File

@@ -4,11 +4,11 @@ import SDWebImageSwiftUI
import SwiftUI
struct VideoBanner: View {
let video: Video
let video: Video?
var playbackTime: CMTime?
var videoDuration: TimeInterval?
init(video: Video, playbackTime: CMTime? = nil, videoDuration: TimeInterval? = nil) {
init(video: Video? = nil, playbackTime: CMTime? = nil, videoDuration: TimeInterval? = nil) {
self.video = video
self.playbackTime = playbackTime
self.videoDuration = videoDuration
@@ -24,14 +24,14 @@ struct VideoBanner: View {
#endif
}
VStack(alignment: .leading, spacing: 4) {
Text(video.title)
Text(video?.title ?? "Unknown title")
.truncationMode(.middle)
.lineLimit(2)
.font(.headline)
.frame(alignment: .leading)
HStack {
Text(video.author)
Text(video?.author ?? "Unknown author")
.lineLimit(1)
Spacer()
@@ -40,7 +40,7 @@ struct VideoBanner: View {
progressView
#endif
if let time = (videoDuration ?? video.length).formattedAsPlaybackTime() {
if let time = (videoDuration ?? video?.length ?? 0).formattedAsPlaybackTime() {
Text(time)
.fontWeight(.light)
}
@@ -71,7 +71,7 @@ struct VideoBanner: View {
}
private var smallThumbnail: some View {
WebImage(url: video.thumbnailURL(quality: .medium))
WebImage(url: video?.thumbnailURL(quality: .medium))
.resizable()
.placeholder {
ProgressView()
@@ -109,7 +109,7 @@ struct VideoBanner: View {
}
private var progressViewTotal: Double {
videoDuration ?? video.length
videoDuration ?? video?.length ?? 1
}
}

View File

@@ -31,12 +31,12 @@ struct PlayerControlsView<Content: View>: View {
}) {
HStack {
VStack(alignment: .leading, spacing: 3) {
Text(model.currentItem?.video.title ?? "Not playing")
Text(model.currentItem?.video?.title ?? "Not playing")
.font(.system(size: 14).bold())
.foregroundColor(model.currentItem.isNil ? .secondary : .accentColor)
.lineLimit(1)
Text(model.currentItem?.video.author ?? "Yattee v0.1")
Text(model.currentItem?.video?.author ?? "Yattee v0.1")
.fontWeight(model.currentItem.isNil ? .light : .bold)
.font(.system(size: 10))
.foregroundColor(.secondary)