fix(native): harden player teardown and shelf recovery
This commit is contained in:
@@ -10,6 +10,14 @@ import QuartzCore
|
||||
import Metal
|
||||
#endif
|
||||
|
||||
struct MpvLifecycleUnavailableError: LocalizedError {
|
||||
let errorDescription: String?
|
||||
|
||||
init(_ description: String) {
|
||||
errorDescription = description
|
||||
}
|
||||
}
|
||||
|
||||
protocol MpvPlayerDelegate: AnyObject {
|
||||
func onPropertyChange(name: String, value: Any?)
|
||||
func onEvent(name: String, data: [String: Any]?)
|
||||
@@ -944,11 +952,7 @@ class MpvPlayerCoreBase: NSObject {
|
||||
pendingRequests.removeAll()
|
||||
pendingRequestsLock.unlock()
|
||||
|
||||
let error = NSError(
|
||||
domain: "mpv",
|
||||
code: -1,
|
||||
userInfo: [NSLocalizedDescriptionKey: "Player disposed"]
|
||||
)
|
||||
let error = MpvLifecycleUnavailableError("Player disposed")
|
||||
for (_, request) in pending {
|
||||
DispatchQueue.main.async {
|
||||
switch request {
|
||||
@@ -977,12 +981,8 @@ class MpvPlayerCoreBase: NSObject {
|
||||
return pendingRequests.removeValue(forKey: requestId)
|
||||
}
|
||||
|
||||
private func lifecycleUnavailableError() -> NSError {
|
||||
NSError(
|
||||
domain: "mpv",
|
||||
code: -1,
|
||||
userInfo: [NSLocalizedDescriptionKey: "Player is not initialized or has been disposed"]
|
||||
)
|
||||
private func lifecycleUnavailableError() -> MpvLifecycleUnavailableError {
|
||||
MpvLifecycleUnavailableError("Player is not initialized or has been disposed")
|
||||
}
|
||||
|
||||
private func mpvError(_ status: CInt) -> NSError {
|
||||
|
||||
@@ -49,11 +49,15 @@ extension MpvPluginShared {
|
||||
self?.didSetPauseProperty(value: value)
|
||||
}
|
||||
result(nil)
|
||||
case .failure:
|
||||
case .failure(let error):
|
||||
let lifecycleUnavailable = error is MpvLifecycleUnavailableError
|
||||
result(
|
||||
FlutterError(
|
||||
code: "SET_PROPERTY_FAILED",
|
||||
message: "MPV rejected or cancelled the property write",
|
||||
code: lifecycleUnavailable ? "NOT_INITIALIZED" : "SET_PROPERTY_FAILED",
|
||||
message:
|
||||
lifecycleUnavailable
|
||||
? "MPV player is not initialized"
|
||||
: "MPV rejected or cancelled the property write",
|
||||
details: nil))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user