From cb81a687bcbebce04446aeb790a8ad62aaad92bf Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Thu, 10 Nov 2022 22:20:44 +0100 Subject: [PATCH] Improve EOF handling with MPV --- Model/Player/Backends/MPVBackend.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Model/Player/Backends/MPVBackend.swift b/Model/Player/Backends/MPVBackend.swift index ab9a6d47..be9e53e4 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -470,7 +470,19 @@ final class MPVBackend: PlayerBackend { isSeeking = true case MPV_EVENT_END_FILE: - DispatchQueue.main.async { [weak self] in self?.handleEndOfFile() } + let reason = event!.pointee.data.load(as: mpv_end_file_reason.self) + + if reason != MPV_END_FILE_REASON_STOP { + DispatchQueue.main.async { [weak self] in + guard let self else { return } + NavigationModel.shared.presentAlert(title: "Error while opening file") + self.model.closeCurrentItem(finished: true) + self.getTimeUpdates() + self.eofPlaybackModeAction() + } + } else { + DispatchQueue.main.async { [weak self] in self?.handleEndOfFile() } + } default: logger.info(.init(stringLiteral: "UNHANDLED event: \(String(cString: mpv_event_name(event.pointee.event_id)))"))