Skip to content

Commit

Permalink
Restart finished video
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stonerl committed Apr 25, 2024
1 parent d1cf45c commit e262d59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Model/Player/Backends/AVPlayerBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() &&
model.playerTime.duration.seconds > 0
{
seek(to: 0, seekType: .loopRestart)
}

avPlayer.play()
model.objectWillChange.send()
}
Expand Down
9 changes: 7 additions & 2 deletions Model/Player/Backends/MPVBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 self.currentTime?.seconds.formattedAsPlaybackTime() == model.playerTime.duration.seconds.formattedAsPlaybackTime() &&
model.playerTime.duration.seconds > 0
{
seek(to: 0, seekType: .loopRestart)
}

client?.play()
}

Expand Down Expand Up @@ -519,8 +526,6 @@ final class MPVBackend: PlayerBackend {
guard client.eofReached else {
return
}

getTimeUpdates()
eofPlaybackModeAction()
}

Expand Down

0 comments on commit e262d59

Please sign in to comment.