Skip to content

Commit

Permalink
Fix autoplay and playing again finished items
Browse files Browse the repository at this point in the history
  • Loading branch information
GianniCarlo committed Dec 5, 2024
1 parent 90cb3ea commit 7d50997
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions BookPlayerWatch/PlayerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,17 @@ extension PlayerManager {

// If book is completed, stop
let playerTime = CMTimeGetSeconds(audioPlayer.currentTime())
if playerTime.isFinite && Int(currentItem.duration) == Int(playerTime) { return }
if playerTime.isFinite && Int(currentItem.duration) == Int(playerTime) {
/// if it was manually selected, restart book
if !autoPlayed {
updatePlaybackTime(item: currentItem, time: 0)
let firstChapter = currentItem.chapters.first!
currentItem.currentChapter = firstChapter
loadChapterMetadata(firstChapter, autoplay: true)
} else {
return
}
}

handleSmartRewind(currentItem)

Expand Down Expand Up @@ -988,12 +998,12 @@ extension PlayerManager {
}

func playNextItem(autoPlayed: Bool = false, shouldAutoplay: Bool = true) {
/// If it's autoplayed, check if setting is enabled
if autoPlayed,
!UserDefaults.standard.bool(forKey: Constants.UserDefaults.autoplayEnabled)
{
return
}
/// If it's autoplayed, check if setting is enabled (disabled on watch app for the time being)
// if autoPlayed,
// !UserDefaults.standard.bool(forKey: Constants.UserDefaults.autoplayEnabled)
// {
// return
// }

let restartFinished = UserDefaults.standard.bool(forKey: Constants.UserDefaults.autoplayRestartEnabled)

Expand Down

0 comments on commit 7d50997

Please sign in to comment.