From 86b91916a74bb4207282d8827dd30b7affbc86f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20F=C3=B6rster?= Date: Thu, 25 Apr 2024 19:43:28 +0200 Subject: [PATCH] Restart finished video After the video has ended, hitting play restarts the video from the beginning fixes #449 If I understand the issue correctly, however, videos can now be played again without hitting the "Start from the beginning" button. --- Model/Player/Backends/AVPlayerBackend.swift | 7 +++++++ Model/Player/Backends/MPVBackend.swift | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Model/Player/Backends/AVPlayerBackend.swift b/Model/Player/Backends/AVPlayerBackend.swift index 7e71208f..576fc78d 100644 --- a/Model/Player/Backends/AVPlayerBackend.swift +++ b/Model/Player/Backends/AVPlayerBackend.swift @@ -160,6 +160,13 @@ final class AVPlayerBackend: PlayerBackend { return } + // After the video has ended, hitting play restarts the video from the beginning. + if currentTime?.seconds.formattedAsPlaybackTime() == model.playerTime.duration.seconds.formattedAsPlaybackTime() && + currentTime!.seconds > 0 && model.playerTime.duration.seconds > 0 + { + seek(to: 0, seekType: .loopRestart) + } + avPlayer.play() model.objectWillChange.send() } diff --git a/Model/Player/Backends/MPVBackend.swift b/Model/Player/Backends/MPVBackend.swift index c8457946..6f25172a 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -354,6 +354,13 @@ final class MPVBackend: PlayerBackend { setRate(model.currentRate) + // After the video has ended, hitting play restarts the video from the beginning. + if currentTime?.seconds.formattedAsPlaybackTime() == model.playerTime.duration.seconds.formattedAsPlaybackTime() && + currentTime!.seconds > 0 && model.playerTime.duration.seconds > 0 + { + seek(to: 0, seekType: .loopRestart) + } + client?.play() } @@ -519,8 +526,6 @@ final class MPVBackend: PlayerBackend { guard client.eofReached else { return } - - getTimeUpdates() eofPlaybackModeAction() }