diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 1da1d8c8..e6c33702 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -131,8 +131,7 @@ final class PlayerModel: ObservableObject { @Default(.rotateToLandscapeOnEnterFullScreen) private var rotateToLandscapeOnEnterFullScreen #endif - @Published var playedChapters: [Int] = [] - @Published var currentChapterIndex: Int? + @Published var currentChapter: Int? var accounts: AccountsModel { .shared } var comments: CommentsModel { .shared } diff --git a/Shared/Player/Video Details/ChapterView.swift b/Shared/Player/Video Details/ChapterView.swift index 97f85eb3..52e2dc35 100644 --- a/Shared/Player/Video Details/ChapterView.swift +++ b/Shared/Player/Video Details/ChapterView.swift @@ -12,11 +12,7 @@ import SwiftUI @ObservedObject private var player = PlayerModel.shared var isCurrentChapter: Bool { - player.currentChapterIndex == chapterIndex - } - - var hasBeenPlayed: Bool { - player.playedChapters.contains(chapterIndex) + player.currentChapter == chapterIndex } var body: some View { @@ -35,6 +31,7 @@ import SwiftUI .buttonStyle(.plain) .onReceive(PlayerTimeModel.shared.$currentTime) { cmTime in self.handleTimeUpdate(cmTime) + print("currentChapterIndex:", player.currentChapter ?? 0) } } @@ -80,10 +77,7 @@ import SwiftUI private func handleTimeUpdate(_ cmTime: CMTime) { let time = CMTimeGetSeconds(cmTime) if time >= chapter.start, nextChapterStart == nil || time < nextChapterStart! { - player.currentChapterIndex = chapterIndex - if !player.playedChapters.contains(chapterIndex) { - player.playedChapters.append(chapterIndex) - } + player.currentChapter = chapterIndex } } }