subscribe chapters to currentTime notification

This commit is contained in:
Toni Förster
2023-12-04 00:07:39 +01:00
parent aa5d6733b2
commit 586cea7d44
2 changed files with 18 additions and 7 deletions

View File

@@ -18,10 +18,6 @@ import SwiftUI
var body: some View {
Button(action: {
player.backend.seek(to: chapter.start, seekType: .userInteracted)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { // Introducing a delay to give the player a chance to skip to the chapter
PlayerTimeModel.shared.currentTime = CMTime(seconds: chapter.start, preferredTimescale: 1)
handleTimeUpdate(PlayerTimeModel.shared.currentTime)
}
}) {
Group {
verticalChapter
@@ -29,9 +25,14 @@ import SwiftUI
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.onReceive(PlayerTimeModel.shared.$currentTime) { cmTime in
self.handleTimeUpdate(cmTime)
print("currentChapterIndex:", player.currentChapter ?? 0)
.onReceive(
NotificationCenter.default
.publisher(for: .getTimeUpdatesNotification)
.receive(on: DispatchQueue.main)
) { notification in
if let cmTime = notification.object as? CMTime {
self.handleTimeUpdate(cmTime)
}
}
}