mirror of
https://github.com/yattee/yattee.git
synced 2025-04-25 08:06:31 +00:00
Video playback progress and restoring time for previously played
This commit is contained in:
parent
bc065e282a
commit
4307da57c5
17
Extensions/Double+Format.swift
Normal file
17
Extensions/Double+Format.swift
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
extension Double {
|
||||||
|
func formattedAsPlaybackTime() -> String? {
|
||||||
|
guard !isZero else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let formatter = DateComponentsFormatter()
|
||||||
|
|
||||||
|
formatter.unitsStyle = .positional
|
||||||
|
formatter.allowedUnits = self >= (60 * 60) ? [.hour, .minute, .second] : [.minute, .second]
|
||||||
|
formatter.zeroFormattingBehavior = [.pad]
|
||||||
|
|
||||||
|
return formatter.string(from: self)
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,6 @@ final class PlayerModel: ObservableObject {
|
|||||||
@Published var queue = [PlayerQueueItem]()
|
@Published var queue = [PlayerQueueItem]()
|
||||||
@Published var currentItem: PlayerQueueItem!
|
@Published var currentItem: PlayerQueueItem!
|
||||||
@Published var live = false
|
@Published var live = false
|
||||||
@Published var time: CMTime?
|
|
||||||
|
|
||||||
@Published var history = [PlayerQueueItem]()
|
@Published var history = [PlayerQueueItem]()
|
||||||
|
|
||||||
@ -58,6 +57,18 @@ final class PlayerModel: ObservableObject {
|
|||||||
player.timeControlStatus == .playing
|
player.timeControlStatus == .playing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var time: CMTime? {
|
||||||
|
currentItem?.playbackTime
|
||||||
|
}
|
||||||
|
|
||||||
|
var playerItemDuration: CMTime? {
|
||||||
|
player.currentItem?.asset.duration
|
||||||
|
}
|
||||||
|
|
||||||
|
var videoDuration: TimeInterval? {
|
||||||
|
currentItem?.duration ?? currentVideo?.length
|
||||||
|
}
|
||||||
|
|
||||||
func togglePlay() {
|
func togglePlay() {
|
||||||
isPlaying ? pause() : play()
|
isPlaying ? pause() : play()
|
||||||
}
|
}
|
||||||
@ -78,8 +89,8 @@ final class PlayerModel: ObservableObject {
|
|||||||
player.pause()
|
player.pause()
|
||||||
}
|
}
|
||||||
|
|
||||||
func playVideo(_ video: Video) {
|
func playVideo(_ video: Video, time: CMTime? = nil) {
|
||||||
savedTime = nil
|
savedTime = time
|
||||||
shouldResumePlaying = true
|
shouldResumePlaying = true
|
||||||
|
|
||||||
loadAvailableStreams(video) { streams in
|
loadAvailableStreams(video) { streams in
|
||||||
@ -88,33 +99,32 @@ final class PlayerModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.streamSelection = stream
|
self.streamSelection = stream
|
||||||
self.playStream(stream, of: video, forcePlay: true)
|
self.playStream(stream, of: video, preservingTime: !time.isNil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func upgradeToStream(_ stream: Stream) {
|
func upgradeToStream(_ stream: Stream) {
|
||||||
if !self.stream.isNil, self.stream != stream {
|
if !self.stream.isNil, self.stream != stream {
|
||||||
playStream(stream, of: currentItem.video, preservingTime: true)
|
playStream(stream, of: currentVideo!, preservingTime: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func playStream(
|
private func playStream(
|
||||||
_ stream: Stream,
|
_ stream: Stream,
|
||||||
of video: Video,
|
of video: Video,
|
||||||
forcePlay: Bool = false,
|
|
||||||
preservingTime: Bool = false
|
preservingTime: Bool = false
|
||||||
) {
|
) {
|
||||||
if let url = stream.singleAssetURL {
|
if let url = stream.singleAssetURL {
|
||||||
logger.info("playing stream with one asset\(stream.kind == .hls ? " (HLS)" : ""): \(url)")
|
logger.info("playing stream with one asset\(stream.kind == .hls ? " (HLS)" : ""): \(url)")
|
||||||
|
|
||||||
insertPlayerItem(stream, for: video, forcePlay: forcePlay, preservingTime: preservingTime)
|
insertPlayerItem(stream, for: video, preservingTime: preservingTime)
|
||||||
} else {
|
} else {
|
||||||
logger.info("playing stream with many assets:")
|
logger.info("playing stream with many assets:")
|
||||||
logger.info("composition audio asset: \(stream.audioAsset.url)")
|
logger.info("composition audio asset: \(stream.audioAsset.url)")
|
||||||
logger.info("composition video asset: \(stream.videoAsset.url)")
|
logger.info("composition video asset: \(stream.videoAsset.url)")
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
await self.loadComposition(stream, of: video, forcePlay: forcePlay, preservingTime: preservingTime)
|
await self.loadComposition(stream, of: video, preservingTime: preservingTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,51 +132,58 @@ final class PlayerModel: ObservableObject {
|
|||||||
private func insertPlayerItem(
|
private func insertPlayerItem(
|
||||||
_ stream: Stream,
|
_ stream: Stream,
|
||||||
for video: Video,
|
for video: Video,
|
||||||
forcePlay: Bool = false,
|
|
||||||
preservingTime: Bool = false
|
preservingTime: Bool = false
|
||||||
) {
|
) {
|
||||||
let playerItem = playerItem(stream)
|
let playerItem = playerItem(stream)
|
||||||
|
|
||||||
guard playerItem != nil else {
|
guard playerItem != nil else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
attachMetadata(to: playerItem!, video: video, for: stream)
|
attachMetadata(to: playerItem!, video: video, for: stream)
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.stream = stream
|
self.stream = stream
|
||||||
self.composition = AVMutableComposition()
|
self.composition = AVMutableComposition()
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldResumePlaying = forcePlay || isPlaying
|
let replaceItemAndSeek = {
|
||||||
|
self.player.replaceCurrentItem(with: playerItem)
|
||||||
|
self.seekToSavedTime { finished in
|
||||||
|
guard finished else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.savedTime = nil
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
||||||
|
self.play()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let startPlaying = {
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
||||||
|
self.play()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if preservingTime {
|
if preservingTime {
|
||||||
saveTime {
|
if savedTime.isNil {
|
||||||
self.player.replaceCurrentItem(with: playerItem)
|
saveTime {
|
||||||
|
replaceItemAndSeek()
|
||||||
self.seekToSavedTime { finished in
|
startPlaying()
|
||||||
guard finished else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
||||||
forcePlay || self.shouldResumePlaying ? self.play() : self.pause()
|
|
||||||
self.shouldResumePlaying = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
replaceItemAndSeek()
|
||||||
|
startPlaying()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
player.replaceCurrentItem(with: playerItem)
|
player.replaceCurrentItem(with: playerItem)
|
||||||
|
startPlaying()
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
||||||
forcePlay || self.shouldResumePlaying ? self.play() : self.pause()
|
|
||||||
self.shouldResumePlaying = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func loadComposition(
|
private func loadComposition(
|
||||||
_ stream: Stream,
|
_ stream: Stream,
|
||||||
of video: Video,
|
of video: Video,
|
||||||
forcePlay: Bool = false,
|
|
||||||
preservingTime: Bool = false
|
preservingTime: Bool = false
|
||||||
) async {
|
) async {
|
||||||
await loadCompositionAsset(stream.audioAsset, type: .audio, of: video)
|
await loadCompositionAsset(stream.audioAsset, type: .audio, of: video)
|
||||||
@ -177,7 +194,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
insertPlayerItem(stream, for: video, forcePlay: forcePlay, preservingTime: preservingTime)
|
insertPlayerItem(stream, for: video, preservingTime: preservingTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func loadCompositionAsset(_ asset: AVURLAsset, type: AVMediaType, of video: Video) async {
|
private func loadCompositionAsset(_ asset: AVURLAsset, type: AVMediaType, of video: Video) async {
|
||||||
@ -274,6 +291,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
|
|
||||||
@objc func itemDidPlayToEndTime() {
|
@objc func itemDidPlayToEndTime() {
|
||||||
if queue.isEmpty {
|
if queue.isEmpty {
|
||||||
|
addCurrentItemToHistory()
|
||||||
resetQueue()
|
resetQueue()
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
avPlayerViewController!.dismiss(animated: true) {
|
avPlayerViewController!.dismiss(animated: true) {
|
||||||
@ -318,7 +336,8 @@ final class PlayerModel: ObservableObject {
|
|||||||
timeObserver = player.addPeriodicTimeObserver(forInterval: interval, queue: .main) { _ in
|
timeObserver = player.addPeriodicTimeObserver(forInterval: interval, queue: .main) { _ in
|
||||||
self.currentRate = self.player.rate
|
self.currentRate = self.player.rate
|
||||||
self.live = self.currentVideo?.live ?? false
|
self.live = self.currentVideo?.live ?? false
|
||||||
self.time = self.player.currentTime()
|
self.currentItem?.playbackTime = self.player.currentTime()
|
||||||
|
self.currentItem?.videoDuration = self.player.currentItem?.asset.duration.seconds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,12 +37,15 @@ extension PlayerModel {
|
|||||||
|
|
||||||
func playItem(_ item: PlayerQueueItem, video: Video? = nil) {
|
func playItem(_ item: PlayerQueueItem, video: Video? = nil) {
|
||||||
currentItem = item
|
currentItem = item
|
||||||
|
if currentItem.playbackTime.isNil {
|
||||||
|
currentItem.playbackTime = .zero
|
||||||
|
}
|
||||||
|
|
||||||
if video != nil {
|
if video != nil {
|
||||||
currentItem.video = video!
|
currentItem.video = video!
|
||||||
}
|
}
|
||||||
|
|
||||||
playVideo(currentItem.video)
|
playVideo(currentVideo!, time: item.playbackTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
func advanceToNextItem() {
|
func advanceToNextItem() {
|
||||||
@ -54,6 +57,8 @@ extension PlayerModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func advanceToItem(_ newItem: PlayerQueueItem) {
|
func advanceToItem(_ newItem: PlayerQueueItem) {
|
||||||
|
addCurrentItemToHistory()
|
||||||
|
|
||||||
let item = remove(newItem)!
|
let item = remove(newItem)!
|
||||||
loadDetails(newItem.video) { video in
|
loadDetails(newItem.video) { video in
|
||||||
self.playItem(item, video: video)
|
self.playItem(item, video: video)
|
||||||
@ -86,10 +91,11 @@ extension PlayerModel {
|
|||||||
@discardableResult func enqueueVideo(
|
@discardableResult func enqueueVideo(
|
||||||
_ video: Video,
|
_ video: Video,
|
||||||
play: Bool = false,
|
play: Bool = false,
|
||||||
|
atTime: CMTime? = nil,
|
||||||
prepending: Bool = false,
|
prepending: Bool = false,
|
||||||
videoDetailsLoadHandler: @escaping (Video, PlayerQueueItem) -> Void = { _, _ in }
|
videoDetailsLoadHandler: @escaping (Video, PlayerQueueItem) -> Void = { _, _ in }
|
||||||
) -> PlayerQueueItem? {
|
) -> PlayerQueueItem? {
|
||||||
let item = PlayerQueueItem(video)
|
let item = PlayerQueueItem(video, playbackTime: atTime)
|
||||||
|
|
||||||
queue.insert(item, at: prepending ? 0 : queue.endIndex)
|
queue.insert(item, at: prepending ? 0 : queue.endIndex)
|
||||||
|
|
||||||
@ -117,13 +123,23 @@ extension PlayerModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addCurrentItemToHistory() {
|
func addCurrentItemToHistory() {
|
||||||
if let item = currentItem, !history.contains(where: { $0.video.videoID == item.video.videoID }) {
|
if let item = currentItem {
|
||||||
|
if let index = history.firstIndex(where: { $0.video.videoID == item.video.videoID }) {
|
||||||
|
history.remove(at: index)
|
||||||
|
}
|
||||||
|
|
||||||
history.insert(item, at: 0)
|
history.insert(item, at: 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func playHistory(_ item: PlayerQueueItem) {
|
func playHistory(_ item: PlayerQueueItem) {
|
||||||
let newItem = enqueueVideo(item.video, prepending: true)
|
var time = item.playbackTime
|
||||||
|
|
||||||
|
if item.shouldRestartPlaying {
|
||||||
|
time = .zero
|
||||||
|
}
|
||||||
|
|
||||||
|
let newItem = enqueueVideo(item.video, atTime: time, prepending: true)
|
||||||
|
|
||||||
advanceToItem(newItem!)
|
advanceToItem(newItem!)
|
||||||
|
|
||||||
|
@ -4,10 +4,28 @@ import Foundation
|
|||||||
struct PlayerQueueItem: Hashable, Identifiable {
|
struct PlayerQueueItem: Hashable, Identifiable {
|
||||||
var id = UUID()
|
var id = UUID()
|
||||||
var video: Video
|
var video: Video
|
||||||
|
var playbackTime: CMTime?
|
||||||
|
var videoDuration: TimeInterval?
|
||||||
|
|
||||||
init(_ video: Video) {
|
init(_ video: Video, playbackTime: CMTime? = nil, videoDuration: TimeInterval? = nil) {
|
||||||
self.video = video
|
self.video = video
|
||||||
|
self.playbackTime = playbackTime
|
||||||
|
self.videoDuration = videoDuration
|
||||||
}
|
}
|
||||||
|
|
||||||
var playerItems = [AVPlayerItem]()
|
var duration: TimeInterval {
|
||||||
|
videoDuration ?? video.length
|
||||||
|
}
|
||||||
|
|
||||||
|
var shouldRestartPlaying: Bool {
|
||||||
|
guard let seconds = playbackTime?.seconds else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return duration - seconds <= 10
|
||||||
|
}
|
||||||
|
|
||||||
|
func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,6 +112,10 @@ extension PlayerModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func streamsSorter(_ lhs: Stream, _ rhs: Stream) -> Bool {
|
func streamsSorter(_ lhs: Stream, _ rhs: Stream) -> Bool {
|
||||||
lhs.kind == rhs.kind ? (lhs.resolution.height > rhs.resolution.height) : (lhs.kind < rhs.kind)
|
if lhs.resolution.isNil || rhs.resolution.isNil {
|
||||||
|
return lhs.kind < rhs.kind
|
||||||
|
}
|
||||||
|
|
||||||
|
return lhs.kind == rhs.kind ? (lhs.resolution.height > rhs.resolution.height) : (lhs.kind < rhs.kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,20 +72,6 @@ struct Video: Identifiable, Equatable, Hashable {
|
|||||||
self.streams = streams
|
self.streams = streams
|
||||||
}
|
}
|
||||||
|
|
||||||
var playTime: String? {
|
|
||||||
guard !length.isZero else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
let formatter = DateComponentsFormatter()
|
|
||||||
|
|
||||||
formatter.unitsStyle = .positional
|
|
||||||
formatter.allowedUnits = length >= (60 * 60) ? [.hour, .minute, .second] : [.minute, .second]
|
|
||||||
formatter.zeroFormattingBehavior = [.pad]
|
|
||||||
|
|
||||||
return formatter.string(from: length)
|
|
||||||
}
|
|
||||||
|
|
||||||
var publishedDate: String? {
|
var publishedDate: String? {
|
||||||
(published.isEmpty || published == "0 seconds ago") ? nil : published
|
(published.isEmpty || published == "0 seconds ago") ? nil : published
|
||||||
}
|
}
|
||||||
|
@ -265,6 +265,9 @@
|
|||||||
37BE0BDC26A2367F0092E2DB /* Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BE0BDB26A2367F0092E2DB /* Player.swift */; };
|
37BE0BDC26A2367F0092E2DB /* Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BE0BDB26A2367F0092E2DB /* Player.swift */; };
|
||||||
37C194C726F6A9C8005D3B96 /* RecentsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C194C626F6A9C8005D3B96 /* RecentsModel.swift */; };
|
37C194C726F6A9C8005D3B96 /* RecentsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C194C626F6A9C8005D3B96 /* RecentsModel.swift */; };
|
||||||
37C194C826F6A9C8005D3B96 /* RecentsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C194C626F6A9C8005D3B96 /* RecentsModel.swift */; };
|
37C194C826F6A9C8005D3B96 /* RecentsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C194C626F6A9C8005D3B96 /* RecentsModel.swift */; };
|
||||||
|
37C3A241272359900087A57A /* Double+Format.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C3A240272359900087A57A /* Double+Format.swift */; };
|
||||||
|
37C3A242272359900087A57A /* Double+Format.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C3A240272359900087A57A /* Double+Format.swift */; };
|
||||||
|
37C3A243272359900087A57A /* Double+Format.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C3A240272359900087A57A /* Double+Format.swift */; };
|
||||||
37C7A1D5267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A1D4267BFD9D0010EAD6 /* SponsorBlockSegment.swift */; };
|
37C7A1D5267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A1D4267BFD9D0010EAD6 /* SponsorBlockSegment.swift */; };
|
||||||
37C7A1D6267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A1D4267BFD9D0010EAD6 /* SponsorBlockSegment.swift */; };
|
37C7A1D6267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A1D4267BFD9D0010EAD6 /* SponsorBlockSegment.swift */; };
|
||||||
37C7A1D7267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A1D4267BFD9D0010EAD6 /* SponsorBlockSegment.swift */; };
|
37C7A1D7267BFD9D0010EAD6 /* SponsorBlockSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C7A1D4267BFD9D0010EAD6 /* SponsorBlockSegment.swift */; };
|
||||||
@ -473,6 +476,7 @@
|
|||||||
37BE0BD926A214630092E2DB /* PlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerViewController.swift; sourceTree = "<group>"; };
|
37BE0BD926A214630092E2DB /* PlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerViewController.swift; sourceTree = "<group>"; };
|
||||||
37BE0BDB26A2367F0092E2DB /* Player.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Player.swift; sourceTree = "<group>"; };
|
37BE0BDB26A2367F0092E2DB /* Player.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Player.swift; sourceTree = "<group>"; };
|
||||||
37C194C626F6A9C8005D3B96 /* RecentsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentsModel.swift; sourceTree = "<group>"; };
|
37C194C626F6A9C8005D3B96 /* RecentsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentsModel.swift; sourceTree = "<group>"; };
|
||||||
|
37C3A240272359900087A57A /* Double+Format.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Double+Format.swift"; sourceTree = "<group>"; };
|
||||||
37C7A1D4267BFD9D0010EAD6 /* SponsorBlockSegment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SponsorBlockSegment.swift; sourceTree = "<group>"; };
|
37C7A1D4267BFD9D0010EAD6 /* SponsorBlockSegment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SponsorBlockSegment.swift; sourceTree = "<group>"; };
|
||||||
37CC3F44270CE30600608308 /* PlayerQueueItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerQueueItem.swift; sourceTree = "<group>"; };
|
37CC3F44270CE30600608308 /* PlayerQueueItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerQueueItem.swift; sourceTree = "<group>"; };
|
||||||
37CC3F4B270CFE1700608308 /* PlayerQueueView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerQueueView.swift; sourceTree = "<group>"; };
|
37CC3F4B270CFE1700608308 /* PlayerQueueView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerQueueView.swift; sourceTree = "<group>"; };
|
||||||
@ -799,6 +803,7 @@
|
|||||||
children = (
|
children = (
|
||||||
379775922689365600DD52A8 /* Array+Next.swift */,
|
379775922689365600DD52A8 /* Array+Next.swift */,
|
||||||
376578842685429C00D4EA09 /* CaseIterable+Next.swift */,
|
376578842685429C00D4EA09 /* CaseIterable+Next.swift */,
|
||||||
|
37C3A240272359900087A57A /* Double+Format.swift */,
|
||||||
37BA794E26DC3E0E002A0235 /* Int+Format.swift */,
|
37BA794E26DC3E0E002A0235 /* Int+Format.swift */,
|
||||||
377A20A82693C9A2002842B8 /* TypedContentAccessors.swift */,
|
377A20A82693C9A2002842B8 /* TypedContentAccessors.swift */,
|
||||||
3743CA51270F284F00E4D32B /* View+Borders.swift */,
|
3743CA51270F284F00E4D32B /* View+Borders.swift */,
|
||||||
@ -1446,6 +1451,7 @@
|
|||||||
37484C1D26FC83A400287258 /* InstancesSettingsView.swift in Sources */,
|
37484C1D26FC83A400287258 /* InstancesSettingsView.swift in Sources */,
|
||||||
37BD07BB2698AB60003EBB87 /* AppSidebarNavigation.swift in Sources */,
|
37BD07BB2698AB60003EBB87 /* AppSidebarNavigation.swift in Sources */,
|
||||||
37D4B0E42671614900C925CA /* PearvidiousApp.swift in Sources */,
|
37D4B0E42671614900C925CA /* PearvidiousApp.swift in Sources */,
|
||||||
|
37C3A241272359900087A57A /* Double+Format.swift in Sources */,
|
||||||
37FB285E272225E800A57617 /* ContentItemView.swift in Sources */,
|
37FB285E272225E800A57617 /* ContentItemView.swift in Sources */,
|
||||||
3797758B2689345500DD52A8 /* Store.swift in Sources */,
|
3797758B2689345500DD52A8 /* Store.swift in Sources */,
|
||||||
37732FF02703A26300F04329 /* ValidationStatusView.swift in Sources */,
|
37732FF02703A26300F04329 /* ValidationStatusView.swift in Sources */,
|
||||||
@ -1502,6 +1508,7 @@
|
|||||||
37BD07BC2698AB60003EBB87 /* AppSidebarNavigation.swift in Sources */,
|
37BD07BC2698AB60003EBB87 /* AppSidebarNavigation.swift in Sources */,
|
||||||
3748186F26A769D60084E870 /* DetailBadge.swift in Sources */,
|
3748186F26A769D60084E870 /* DetailBadge.swift in Sources */,
|
||||||
372915E72687E3B900F5A35B /* Defaults.swift in Sources */,
|
372915E72687E3B900F5A35B /* Defaults.swift in Sources */,
|
||||||
|
37C3A242272359900087A57A /* Double+Format.swift in Sources */,
|
||||||
37DD87C8271C9CFE0027CBF9 /* PlayerStreams.swift in Sources */,
|
37DD87C8271C9CFE0027CBF9 /* PlayerStreams.swift in Sources */,
|
||||||
376578922685490700D4EA09 /* PlaylistsView.swift in Sources */,
|
376578922685490700D4EA09 /* PlaylistsView.swift in Sources */,
|
||||||
37484C2626FC83E000287258 /* InstanceFormView.swift in Sources */,
|
37484C2626FC83E000287258 /* InstanceFormView.swift in Sources */,
|
||||||
@ -1602,6 +1609,7 @@
|
|||||||
37DD87C9271C9CFE0027CBF9 /* PlayerStreams.swift in Sources */,
|
37DD87C9271C9CFE0027CBF9 /* PlayerStreams.swift in Sources */,
|
||||||
375168D82700FDB9008F96A6 /* Debounce.swift in Sources */,
|
375168D82700FDB9008F96A6 /* Debounce.swift in Sources */,
|
||||||
37BA794126DB8F97002A0235 /* ChannelVideosView.swift in Sources */,
|
37BA794126DB8F97002A0235 /* ChannelVideosView.swift in Sources */,
|
||||||
|
37C3A243272359900087A57A /* Double+Format.swift in Sources */,
|
||||||
37AAF29226740715007FC770 /* Channel.swift in Sources */,
|
37AAF29226740715007FC770 /* Channel.swift in Sources */,
|
||||||
37EAD86D267B9C5600D9E01B /* SponsorBlockAPI.swift in Sources */,
|
37EAD86D267B9C5600D9E01B /* SponsorBlockAPI.swift in Sources */,
|
||||||
37732FF22703A26300F04329 /* ValidationStatusView.swift in Sources */,
|
37732FF22703A26300F04329 /* ValidationStatusView.swift in Sources */,
|
||||||
|
@ -25,7 +25,7 @@ struct PlayerQueueRow: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
VideoBanner(video: item.video)
|
VideoBanner(video: item.video, playbackTime: item.playbackTime, videoDuration: item.videoDuration)
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ struct VideoDetails: View {
|
|||||||
|
|
||||||
var publishedDateSection: some View {
|
var publishedDateSection: some View {
|
||||||
Group {
|
Group {
|
||||||
if let video = player.currentItem.video {
|
if let video = player.currentVideo {
|
||||||
HStack(spacing: 4) {
|
HStack(spacing: 4) {
|
||||||
if let published = video.publishedDate {
|
if let published = video.publishedDate {
|
||||||
Text(published)
|
Text(published)
|
||||||
@ -235,7 +235,7 @@ struct VideoDetails: View {
|
|||||||
|
|
||||||
var countsSection: some View {
|
var countsSection: some View {
|
||||||
Group {
|
Group {
|
||||||
if let video = player.currentItem.video {
|
if let video = player.currentVideo {
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
|
@ -1,14 +1,30 @@
|
|||||||
|
import CoreMedia
|
||||||
import Foundation
|
import Foundation
|
||||||
import SDWebImageSwiftUI
|
import SDWebImageSwiftUI
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct VideoBanner: View {
|
struct VideoBanner: View {
|
||||||
let video: Video
|
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 {
|
var body: some View {
|
||||||
HStack(alignment: .center, spacing: 12) {
|
HStack(alignment: .top, spacing: 12) {
|
||||||
smallThumbnail
|
VStack(spacing: thumbnailStackSpacing) {
|
||||||
|
smallThumbnail
|
||||||
|
|
||||||
|
if !playbackTime.isNil {
|
||||||
|
ProgressView(value: progressViewValue, total: progressViewTotal)
|
||||||
|
.progressViewStyle(.linear)
|
||||||
|
.frame(maxWidth: thumbnailWidth)
|
||||||
|
}
|
||||||
|
}
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
Text(video.title)
|
Text(video.title)
|
||||||
.truncationMode(.middle)
|
.truncationMode(.middle)
|
||||||
@ -22,20 +38,29 @@ struct VideoBanner: View {
|
|||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
if let time = video.playTime {
|
if let time = (videoDuration ?? video.length).formattedAsPlaybackTime() {
|
||||||
Text(time)
|
Text(time)
|
||||||
.fontWeight(.light)
|
.fontWeight(.light)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
|
.padding(.vertical, playbackTime.isNil ? 0 : 5)
|
||||||
}
|
}
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 100, alignment: .center)
|
.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))
|
WebImage(url: video.thumbnailURL(quality: .medium))
|
||||||
.resizable()
|
.resizable()
|
||||||
.placeholder {
|
.placeholder {
|
||||||
@ -43,19 +68,35 @@ struct VideoBanner: View {
|
|||||||
}
|
}
|
||||||
.indicator(.activity)
|
.indicator(.activity)
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
.frame(width: 177, height: 100)
|
.frame(width: thumbnailWidth, height: 100)
|
||||||
.mask(RoundedRectangle(cornerRadius: 12))
|
.mask(RoundedRectangle(cornerRadius: 12))
|
||||||
#else
|
#else
|
||||||
.frame(width: 88, height: 50)
|
.frame(width: thumbnailWidth, height: 50)
|
||||||
.mask(RoundedRectangle(cornerRadius: 6))
|
.mask(RoundedRectangle(cornerRadius: 6))
|
||||||
#endif
|
#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 {
|
struct VideoBanner_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
VStack(spacing: 20) {
|
VStack(spacing: 20) {
|
||||||
VideoBanner(video: Video.fixture)
|
VideoBanner(video: Video.fixture, playbackTime: CMTime(seconds: 400, preferredTimescale: 10000))
|
||||||
VideoBanner(video: Video.fixtureUpcomingWithoutPublishedOrViews)
|
VideoBanner(video: Video.fixtureUpcomingWithoutPublishedOrViews)
|
||||||
}
|
}
|
||||||
.frame(maxWidth: 900)
|
.frame(maxWidth: 900)
|
||||||
|
@ -104,13 +104,13 @@ struct VideoCell: View {
|
|||||||
.frame(minHeight: 180)
|
.frame(minHeight: 180)
|
||||||
|
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
if video.playTime != nil || video.live || video.upcoming {
|
if let time = video.length.formattedAsPlaybackTime() || video.live || video.upcoming {
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
VStack(alignment: .center) {
|
VStack(alignment: .center) {
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
if let time = video.playTime {
|
if let time = video.length.formattedAsPlaybackTime() {
|
||||||
HStack(spacing: 4) {
|
HStack(spacing: 4) {
|
||||||
Image(systemName: "clock")
|
Image(systemName: "clock")
|
||||||
Text(time)
|
Text(time)
|
||||||
@ -204,7 +204,7 @@ struct VideoCell: View {
|
|||||||
HStack(alignment: .top) {
|
HStack(alignment: .top) {
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
if let time = video.playTime {
|
if let time = video.length.formattedAsPlaybackTime() {
|
||||||
DetailBadge(text: time, style: .prominent)
|
DetailBadge(text: time, style: .prominent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,32 +56,46 @@ struct PlayerControlsView<Content: View>: View {
|
|||||||
.keyboardShortcut("o")
|
.keyboardShortcut("o")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Group {
|
ZStack(alignment: .bottom) {
|
||||||
if model.isPlaying {
|
HStack {
|
||||||
Button(action: {
|
Group {
|
||||||
model.pause()
|
if model.isPlaying {
|
||||||
}) {
|
Button(action: {
|
||||||
Label("Pause", systemImage: "pause.fill")
|
model.pause()
|
||||||
|
}) {
|
||||||
|
Label("Pause", systemImage: "pause.fill")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Button(action: {
|
||||||
|
model.play()
|
||||||
|
}) {
|
||||||
|
Label("Play", systemImage: "play.fill")
|
||||||
|
}
|
||||||
|
.disabled(model.player.currentItem.isNil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
.frame(minWidth: 30)
|
||||||
Button(action: {
|
.scaleEffect(1.7)
|
||||||
model.play()
|
#if !os(tvOS)
|
||||||
}) {
|
.keyboardShortcut("p")
|
||||||
Label("Play", systemImage: "play.fill")
|
#endif
|
||||||
}
|
|
||||||
.disabled(model.player.currentItem.isNil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.frame(minWidth: 30)
|
|
||||||
.scaleEffect(1.7)
|
|
||||||
#if !os(tvOS)
|
|
||||||
.keyboardShortcut("p")
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Button(action: { model.advanceToNextItem() }) {
|
Button(action: { model.advanceToNextItem() }) {
|
||||||
Label("Next", systemImage: "forward.fill")
|
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)
|
.buttonStyle(.plain)
|
||||||
.labelStyle(.iconOnly)
|
.labelStyle(.iconOnly)
|
||||||
@ -97,6 +111,14 @@ struct PlayerControlsView<Content: View>: View {
|
|||||||
})
|
})
|
||||||
#endif
|
#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 {
|
struct PlayerControlsView_Previews: PreviewProvider {
|
||||||
|
@ -29,7 +29,6 @@ struct NowPlayingView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onPlayPauseCommand(perform: player.togglePlay)
|
.onPlayPauseCommand(perform: player.togglePlay)
|
||||||
|
|
||||||
.padding(.bottom, 20)
|
.padding(.bottom, 20)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +71,7 @@ struct NowPlayingView: View {
|
|||||||
player.playHistory(item)
|
player.playHistory(item)
|
||||||
player.presentPlayer()
|
player.presentPlayer()
|
||||||
} label: {
|
} label: {
|
||||||
VideoBanner(video: item.video)
|
VideoBanner(video: item.video, playbackTime: item.playbackTime, videoDuration: item.videoDuration)
|
||||||
}
|
}
|
||||||
.contextMenu {
|
.contextMenu {
|
||||||
Button("Delete", role: .destructive) {
|
Button("Delete", role: .destructive) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user