mirror of
https://github.com/yattee/yattee.git
synced 2024-12-14 14:20:32 +05:30
Video loading errors reporting
This commit is contained in:
parent
29d8155bea
commit
b2fa5c2620
@ -58,14 +58,22 @@ protocol VideosAPI {
|
||||
|
||||
func channelPlaylist(_ id: String) -> Resource?
|
||||
|
||||
func loadDetails(_ item: PlayerQueueItem, completionHandler: @escaping (PlayerQueueItem) -> Void)
|
||||
func loadDetails(
|
||||
_ item: PlayerQueueItem,
|
||||
failureHandler: ((RequestError) -> Void)?,
|
||||
completionHandler: @escaping (PlayerQueueItem) -> Void
|
||||
)
|
||||
func shareURL(_ item: ContentItem, frontendHost: String?, time: CMTime?) -> URL?
|
||||
|
||||
func comments(_ id: Video.ID, page: String?) -> Resource?
|
||||
}
|
||||
|
||||
extension VideosAPI {
|
||||
func loadDetails(_ item: PlayerQueueItem, completionHandler: @escaping (PlayerQueueItem) -> Void = { _ in }) {
|
||||
func loadDetails(
|
||||
_ item: PlayerQueueItem,
|
||||
failureHandler: ((RequestError) -> Void)? = nil,
|
||||
completionHandler: @escaping (PlayerQueueItem) -> Void = { _ in }
|
||||
) {
|
||||
guard (item.video?.streams ?? []).isEmpty else {
|
||||
completionHandler(item)
|
||||
return
|
||||
@ -80,7 +88,7 @@ extension VideosAPI {
|
||||
newItem.video = video
|
||||
|
||||
completionHandler(newItem)
|
||||
}
|
||||
}.onFailure { failureHandler?($0) }
|
||||
}
|
||||
|
||||
func shareURL(_ item: ContentItem, frontendHost: String? = nil, time: CMTime? = nil) -> URL? {
|
||||
|
@ -98,6 +98,8 @@ final class PlayerModel: ObservableObject {
|
||||
backend.networkState.player = self
|
||||
}
|
||||
}}
|
||||
var navigation: NavigationModel
|
||||
|
||||
var context: NSManagedObjectContext = PersistenceController.shared.container.viewContext
|
||||
var backgroundContext = PersistenceController.shared.container.newBackgroundContext()
|
||||
|
||||
@ -134,12 +136,14 @@ final class PlayerModel: ObservableObject {
|
||||
accounts: AccountsModel = AccountsModel(),
|
||||
comments: CommentsModel = CommentsModel(),
|
||||
controls: PlayerControlsModel = PlayerControlsModel(),
|
||||
navigation: NavigationModel = NavigationModel(),
|
||||
playerTime: PlayerTimeModel = PlayerTimeModel(),
|
||||
networkState: NetworkStateModel = NetworkStateModel()
|
||||
) {
|
||||
self.accounts = accounts
|
||||
self.comments = comments
|
||||
self.controls = controls
|
||||
self.navigation = navigation
|
||||
self.playerTime = playerTime
|
||||
self.networkState = networkState
|
||||
|
||||
|
@ -93,7 +93,7 @@ extension PlayerModel {
|
||||
|
||||
currentItem = newItem
|
||||
|
||||
accounts.api.loadDetails(newItem) { newItem in
|
||||
accounts.api.loadDetails(newItem, failureHandler: videoLoadFailureHandler) { newItem in
|
||||
self.playItem(newItem, at: time)
|
||||
}
|
||||
}
|
||||
@ -136,7 +136,7 @@ extension PlayerModel {
|
||||
}
|
||||
|
||||
if loadDetails {
|
||||
accounts.api.loadDetails(item) { [weak self] newItem in
|
||||
accounts.api.loadDetails(item, failureHandler: videoLoadFailureHandler) { [weak self] newItem in
|
||||
guard let self = self else { return }
|
||||
videoDetailsLoadHandler(newItem.video, newItem)
|
||||
|
||||
@ -197,10 +197,16 @@ extension PlayerModel {
|
||||
func loadQueueVideoDetails(_ item: PlayerQueueItem) {
|
||||
guard !accounts.current.isNil, !item.hasDetailsLoaded else { return }
|
||||
|
||||
accounts.api.loadDetails(item) { newItem in
|
||||
accounts.api.loadDetails(item, completionHandler: { newItem in
|
||||
if let index = self.queue.firstIndex(where: { $0.id == item.id }) {
|
||||
self.queue[index] = newItem
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private func videoLoadFailureHandler(_ error: RequestError) {
|
||||
navigation.presentAlert(title: "Could not load video", message: error.userMessage)
|
||||
videoBeingOpened = nil
|
||||
currentItem = nil
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,10 @@ extension PlayerModel {
|
||||
}
|
||||
}
|
||||
.onCompletion(onCompletion)
|
||||
.onFailure { [weak self] responseError in
|
||||
self?.navigation.presentAlert(title: "Could not load streams", message: responseError.userMessage)
|
||||
self?.videoBeingOpened = nil
|
||||
}
|
||||
}
|
||||
|
||||
func streamsWithInstance(instance: Instance, streams: [Stream]) -> [Stream] {
|
||||
|
@ -196,6 +196,7 @@ struct YatteeApp: App {
|
||||
player.accounts = accounts
|
||||
player.comments = comments
|
||||
player.controls = playerControls
|
||||
player.navigation = navigation
|
||||
player.networkState = networkState
|
||||
player.playerTime = playerTime
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user