mirror of
https://github.com/yattee/yattee.git
synced 2024-12-23 14:03:41 +00:00
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 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 shareURL(_ item: ContentItem, frontendHost: String?, time: CMTime?) -> URL?
|
||||||
|
|
||||||
func comments(_ id: Video.ID, page: String?) -> Resource?
|
func comments(_ id: Video.ID, page: String?) -> Resource?
|
||||||
}
|
}
|
||||||
|
|
||||||
extension VideosAPI {
|
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 {
|
guard (item.video?.streams ?? []).isEmpty else {
|
||||||
completionHandler(item)
|
completionHandler(item)
|
||||||
return
|
return
|
||||||
@ -80,7 +88,7 @@ extension VideosAPI {
|
|||||||
newItem.video = video
|
newItem.video = video
|
||||||
|
|
||||||
completionHandler(newItem)
|
completionHandler(newItem)
|
||||||
}
|
}.onFailure { failureHandler?($0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func shareURL(_ item: ContentItem, frontendHost: String? = nil, time: CMTime? = nil) -> URL? {
|
func shareURL(_ item: ContentItem, frontendHost: String? = nil, time: CMTime? = nil) -> URL? {
|
||||||
|
@ -98,6 +98,8 @@ final class PlayerModel: ObservableObject {
|
|||||||
backend.networkState.player = self
|
backend.networkState.player = self
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
var navigation: NavigationModel
|
||||||
|
|
||||||
var context: NSManagedObjectContext = PersistenceController.shared.container.viewContext
|
var context: NSManagedObjectContext = PersistenceController.shared.container.viewContext
|
||||||
var backgroundContext = PersistenceController.shared.container.newBackgroundContext()
|
var backgroundContext = PersistenceController.shared.container.newBackgroundContext()
|
||||||
|
|
||||||
@ -134,12 +136,14 @@ final class PlayerModel: ObservableObject {
|
|||||||
accounts: AccountsModel = AccountsModel(),
|
accounts: AccountsModel = AccountsModel(),
|
||||||
comments: CommentsModel = CommentsModel(),
|
comments: CommentsModel = CommentsModel(),
|
||||||
controls: PlayerControlsModel = PlayerControlsModel(),
|
controls: PlayerControlsModel = PlayerControlsModel(),
|
||||||
|
navigation: NavigationModel = NavigationModel(),
|
||||||
playerTime: PlayerTimeModel = PlayerTimeModel(),
|
playerTime: PlayerTimeModel = PlayerTimeModel(),
|
||||||
networkState: NetworkStateModel = NetworkStateModel()
|
networkState: NetworkStateModel = NetworkStateModel()
|
||||||
) {
|
) {
|
||||||
self.accounts = accounts
|
self.accounts = accounts
|
||||||
self.comments = comments
|
self.comments = comments
|
||||||
self.controls = controls
|
self.controls = controls
|
||||||
|
self.navigation = navigation
|
||||||
self.playerTime = playerTime
|
self.playerTime = playerTime
|
||||||
self.networkState = networkState
|
self.networkState = networkState
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ extension PlayerModel {
|
|||||||
|
|
||||||
currentItem = newItem
|
currentItem = newItem
|
||||||
|
|
||||||
accounts.api.loadDetails(newItem) { newItem in
|
accounts.api.loadDetails(newItem, failureHandler: videoLoadFailureHandler) { newItem in
|
||||||
self.playItem(newItem, at: time)
|
self.playItem(newItem, at: time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ extension PlayerModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if loadDetails {
|
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 }
|
guard let self = self else { return }
|
||||||
videoDetailsLoadHandler(newItem.video, newItem)
|
videoDetailsLoadHandler(newItem.video, newItem)
|
||||||
|
|
||||||
@ -197,10 +197,16 @@ extension PlayerModel {
|
|||||||
func loadQueueVideoDetails(_ item: PlayerQueueItem) {
|
func loadQueueVideoDetails(_ item: PlayerQueueItem) {
|
||||||
guard !accounts.current.isNil, !item.hasDetailsLoaded else { return }
|
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 }) {
|
if let index = self.queue.firstIndex(where: { $0.id == item.id }) {
|
||||||
self.queue[index] = newItem
|
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)
|
.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] {
|
func streamsWithInstance(instance: Instance, streams: [Stream]) -> [Stream] {
|
||||||
|
@ -196,6 +196,7 @@ struct YatteeApp: App {
|
|||||||
player.accounts = accounts
|
player.accounts = accounts
|
||||||
player.comments = comments
|
player.comments = comments
|
||||||
player.controls = playerControls
|
player.controls = playerControls
|
||||||
|
player.navigation = navigation
|
||||||
player.networkState = networkState
|
player.networkState = networkState
|
||||||
player.playerTime = playerTime
|
player.playerTime = playerTime
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user