mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
subscribe chapters to currentTime notification
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user