mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 22:00:31 +05:30
Add retry button to video load error alert
This commit is contained in:
parent
815d0b3ae8
commit
b45ceaec59
@ -2,6 +2,7 @@ import AVKit
|
|||||||
import Defaults
|
import Defaults
|
||||||
import Foundation
|
import Foundation
|
||||||
import Siesta
|
import Siesta
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
extension PlayerModel {
|
extension PlayerModel {
|
||||||
var currentVideo: Video? {
|
var currentVideo: Video? {
|
||||||
@ -154,7 +155,7 @@ extension PlayerModel {
|
|||||||
currentItem.playbackTime = time
|
currentItem.playbackTime = time
|
||||||
|
|
||||||
let playTime = currentItem.shouldRestartPlaying ? CMTime.zero : time
|
let playTime = currentItem.shouldRestartPlaying ? CMTime.zero : time
|
||||||
playerAPI.loadDetails(currentItem, failureHandler: videoLoadFailureHandler) { newItem in
|
playerAPI.loadDetails(currentItem, failureHandler: { self.videoLoadFailureHandler($0, video: self.currentItem.video) }) { newItem in
|
||||||
self.playItem(newItem, at: playTime)
|
self.playItem(newItem, at: playTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,7 +198,7 @@ extension PlayerModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if loadDetails {
|
if loadDetails {
|
||||||
playerAPI.loadDetails(item, failureHandler: videoLoadFailureHandler) { [weak self] newItem in
|
playerAPI.loadDetails(item, failureHandler: { self.videoLoadFailureHandler($0, video: video) }) { [weak self] newItem in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
videoDetailsLoadHandler(newItem.video, newItem)
|
videoDetailsLoadHandler(newItem.video, newItem)
|
||||||
|
|
||||||
@ -303,7 +304,7 @@ extension PlayerModel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private func videoLoadFailureHandler(_ error: RequestError) {
|
private func videoLoadFailureHandler(_ error: RequestError, video: Video? = nil) {
|
||||||
var message = error.userMessage
|
var message = error.userMessage
|
||||||
if let errorDictionary = error.json.dictionaryObject,
|
if let errorDictionary = error.json.dictionaryObject,
|
||||||
let errorMessage = errorDictionary["message"] ?? errorDictionary["error"],
|
let errorMessage = errorDictionary["message"] ?? errorDictionary["error"],
|
||||||
@ -313,7 +314,18 @@ extension PlayerModel {
|
|||||||
message += errorString
|
message += errorString
|
||||||
}
|
}
|
||||||
|
|
||||||
navigation.presentAlert(title: "Could not load video", message: message)
|
let alert = Alert(
|
||||||
|
title: Text("Could not load video"),
|
||||||
|
message: Text(message),
|
||||||
|
primaryButton: .cancel(),
|
||||||
|
secondaryButton: .default(Text("Retry")) { [weak self] in
|
||||||
|
if let self, let video = video {
|
||||||
|
self.enqueueVideo(video, play: true, prepending: true, loadDetails: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
navigation.presentAlert(alert)
|
||||||
advancing = false
|
advancing = false
|
||||||
videoBeingOpened = nil
|
videoBeingOpened = nil
|
||||||
currentItem = nil
|
currentItem = nil
|
||||||
|
Loading…
Reference in New Issue
Block a user