mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Video playback progress and restoring time for previously played
This commit is contained in:
@@ -25,7 +25,7 @@ struct PlayerQueueRow: View {
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
VideoBanner(video: item.video)
|
||||
VideoBanner(video: item.video, playbackTime: item.playbackTime, videoDuration: item.videoDuration)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
@@ -211,7 +211,7 @@ struct VideoDetails: View {
|
||||
|
||||
var publishedDateSection: some View {
|
||||
Group {
|
||||
if let video = player.currentItem.video {
|
||||
if let video = player.currentVideo {
|
||||
HStack(spacing: 4) {
|
||||
if let published = video.publishedDate {
|
||||
Text(published)
|
||||
@@ -235,7 +235,7 @@ struct VideoDetails: View {
|
||||
|
||||
var countsSection: some View {
|
||||
Group {
|
||||
if let video = player.currentItem.video {
|
||||
if let video = player.currentVideo {
|
||||
HStack {
|
||||
Spacer()
|
||||
|
||||
|
@@ -1,14 +1,30 @@
|
||||
import CoreMedia
|
||||
import Foundation
|
||||
import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct VideoBanner: View {
|
||||
let video: Video
|
||||
var playbackTime: CMTime?
|
||||
var videoDuration: TimeInterval?
|
||||
|
||||
init(video: Video, playbackTime: CMTime? = nil, videoDuration: TimeInterval? = nil) {
|
||||
self.video = video
|
||||
self.playbackTime = playbackTime
|
||||
self.videoDuration = videoDuration
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .center, spacing: 12) {
|
||||
smallThumbnail
|
||||
HStack(alignment: .top, spacing: 12) {
|
||||
VStack(spacing: thumbnailStackSpacing) {
|
||||
smallThumbnail
|
||||
|
||||
if !playbackTime.isNil {
|
||||
ProgressView(value: progressViewValue, total: progressViewTotal)
|
||||
.progressViewStyle(.linear)
|
||||
.frame(maxWidth: thumbnailWidth)
|
||||
}
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(video.title)
|
||||
.truncationMode(.middle)
|
||||
@@ -22,20 +38,29 @@ struct VideoBanner: View {
|
||||
|
||||
Spacer()
|
||||
|
||||
if let time = video.playTime {
|
||||
if let time = (videoDuration ?? video.length).formattedAsPlaybackTime() {
|
||||
Text(time)
|
||||
.fontWeight(.light)
|
||||
}
|
||||
}
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
.padding(.vertical, playbackTime.isNil ? 0 : 5)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.buttonStyle(.plain)
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 100, alignment: .center)
|
||||
}
|
||||
|
||||
var smallThumbnail: some View {
|
||||
private var thumbnailStackSpacing: Double {
|
||||
#if os(tvOS)
|
||||
8
|
||||
#else
|
||||
3
|
||||
#endif
|
||||
}
|
||||
|
||||
private var smallThumbnail: some View {
|
||||
WebImage(url: video.thumbnailURL(quality: .medium))
|
||||
.resizable()
|
||||
.placeholder {
|
||||
@@ -43,19 +68,35 @@ struct VideoBanner: View {
|
||||
}
|
||||
.indicator(.activity)
|
||||
#if os(tvOS)
|
||||
.frame(width: 177, height: 100)
|
||||
.frame(width: thumbnailWidth, height: 100)
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
#else
|
||||
.frame(width: 88, height: 50)
|
||||
.frame(width: thumbnailWidth, height: 50)
|
||||
.mask(RoundedRectangle(cornerRadius: 6))
|
||||
#endif
|
||||
}
|
||||
|
||||
private var thumbnailWidth: Double {
|
||||
#if os(tvOS)
|
||||
177
|
||||
#else
|
||||
88
|
||||
#endif
|
||||
}
|
||||
|
||||
private var progressViewValue: Double {
|
||||
[playbackTime?.seconds, videoDuration].compactMap { $0 }.min() ?? 0
|
||||
}
|
||||
|
||||
private var progressViewTotal: Double {
|
||||
videoDuration ?? video.length
|
||||
}
|
||||
}
|
||||
|
||||
struct VideoBanner_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VStack(spacing: 20) {
|
||||
VideoBanner(video: Video.fixture)
|
||||
VideoBanner(video: Video.fixture, playbackTime: CMTime(seconds: 400, preferredTimescale: 10000))
|
||||
VideoBanner(video: Video.fixtureUpcomingWithoutPublishedOrViews)
|
||||
}
|
||||
.frame(maxWidth: 900)
|
||||
|
@@ -104,13 +104,13 @@ struct VideoCell: View {
|
||||
.frame(minHeight: 180)
|
||||
|
||||
#if os(tvOS)
|
||||
if video.playTime != nil || video.live || video.upcoming {
|
||||
if let time = video.length.formattedAsPlaybackTime() || video.live || video.upcoming {
|
||||
Spacer()
|
||||
|
||||
VStack(alignment: .center) {
|
||||
Spacer()
|
||||
|
||||
if let time = video.playTime {
|
||||
if let time = video.length.formattedAsPlaybackTime() {
|
||||
HStack(spacing: 4) {
|
||||
Image(systemName: "clock")
|
||||
Text(time)
|
||||
@@ -204,7 +204,7 @@ struct VideoCell: View {
|
||||
HStack(alignment: .top) {
|
||||
Spacer()
|
||||
|
||||
if let time = video.playTime {
|
||||
if let time = video.length.formattedAsPlaybackTime() {
|
||||
DetailBadge(text: time, style: .prominent)
|
||||
}
|
||||
}
|
||||
|
@@ -56,32 +56,46 @@ struct PlayerControlsView<Content: View>: View {
|
||||
.keyboardShortcut("o")
|
||||
#endif
|
||||
|
||||
Group {
|
||||
if model.isPlaying {
|
||||
Button(action: {
|
||||
model.pause()
|
||||
}) {
|
||||
Label("Pause", systemImage: "pause.fill")
|
||||
ZStack(alignment: .bottom) {
|
||||
HStack {
|
||||
Group {
|
||||
if model.isPlaying {
|
||||
Button(action: {
|
||||
model.pause()
|
||||
}) {
|
||||
Label("Pause", systemImage: "pause.fill")
|
||||
}
|
||||
} else {
|
||||
Button(action: {
|
||||
model.play()
|
||||
}) {
|
||||
Label("Play", systemImage: "play.fill")
|
||||
}
|
||||
.disabled(model.player.currentItem.isNil)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Button(action: {
|
||||
model.play()
|
||||
}) {
|
||||
Label("Play", systemImage: "play.fill")
|
||||
}
|
||||
.disabled(model.player.currentItem.isNil)
|
||||
}
|
||||
}
|
||||
.frame(minWidth: 30)
|
||||
.scaleEffect(1.7)
|
||||
#if !os(tvOS)
|
||||
.keyboardShortcut("p")
|
||||
#endif
|
||||
.frame(minWidth: 30)
|
||||
.scaleEffect(1.7)
|
||||
#if !os(tvOS)
|
||||
.keyboardShortcut("p")
|
||||
#endif
|
||||
|
||||
Button(action: { model.advanceToNextItem() }) {
|
||||
Label("Next", systemImage: "forward.fill")
|
||||
Button(action: { model.advanceToNextItem() }) {
|
||||
Label("Next", systemImage: "forward.fill")
|
||||
}
|
||||
.disabled(model.queue.isEmpty)
|
||||
}
|
||||
|
||||
ProgressView(value: progressViewValue, total: progressViewTotal)
|
||||
.progressViewStyle(.linear)
|
||||
#if os(iOS)
|
||||
.offset(x: 0, y: 15)
|
||||
.frame(maxWidth: 60)
|
||||
#else
|
||||
.offset(x: 0, y: 20)
|
||||
.frame(maxWidth: 70)
|
||||
#endif
|
||||
}
|
||||
.disabled(model.queue.isEmpty)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.labelStyle(.iconOnly)
|
||||
@@ -97,6 +111,14 @@ struct PlayerControlsView<Content: View>: View {
|
||||
})
|
||||
#endif
|
||||
}
|
||||
|
||||
private var progressViewValue: Double {
|
||||
[model.time?.seconds, model.videoDuration].compactMap { $0 }.min() ?? 0
|
||||
}
|
||||
|
||||
private var progressViewTotal: Double {
|
||||
model.playerItemDuration?.seconds ?? model.currentVideo?.length ?? progressViewValue
|
||||
}
|
||||
}
|
||||
|
||||
struct PlayerControlsView_Previews: PreviewProvider {
|
||||
|
Reference in New Issue
Block a user