Opening videos by URL and local files

This commit is contained in:
Arkadiusz Fal
2022-11-10 18:11:28 +01:00
parent 34f7621f36
commit 402d1a2f79
40 changed files with 1158 additions and 126 deletions

View File

@@ -2,6 +2,7 @@ import CoreData
import CoreMedia
import Defaults
import Foundation
import SwiftyJSON
extension PlayerModel {
func historyVideo(_ id: String) -> Video? {
@@ -13,12 +14,37 @@ extension PlayerModel {
return
}
if !Video.VideoID.isValid(id), let url = URL(string: id) {
historyVideos.append(.local(url))
return
}
if historyItemBeingLoaded == nil {
logger.info("loading history details: \(id)")
historyItemBeingLoaded = id
} else {
logger.info("POSTPONING history load: \(id)")
historyItemsToLoad.append(id)
return
}
playerAPI.video(id).load().onSuccess { [weak self] response in
guard let video: Video = response.typedContent() else {
return
guard let self else { return }
if let video: Video = response.typedContent() {
self.historyVideos.append(video)
}
}.onCompletion { _ in
self.logger.info("LOADED history details: \(id)")
if self.historyItemBeingLoaded == id {
self.logger.info("setting no history loaded")
self.historyItemBeingLoaded = nil
}
self?.historyVideos.append(video)
if let id = self.historyItemsToLoad.popLast() {
self.loadHistoryVideoDetails(id)
}
}
}