mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
subscribe chapters to currentTime notification
This commit is contained in:
parent
aa5d6733b2
commit
586cea7d44
@ -191,6 +191,10 @@ final class MPVBackend: PlayerBackend {
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self, name: .getTimeUpdatesNotification, object: self.currentTime)
|
||||
}
|
||||
|
||||
typealias AreInIncreasingOrder = (Stream, Stream) -> Bool
|
||||
|
||||
func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream? {
|
||||
@ -432,6 +436,8 @@ final class MPVBackend: PlayerBackend {
|
||||
timeObserverThrottle.execute {
|
||||
self.model.updateWatch(time: self.currentTime)
|
||||
}
|
||||
|
||||
NotificationCenter.default.post(name: .getTimeUpdatesNotification, object: self.currentTime)
|
||||
}
|
||||
|
||||
private func stopClientUpdates() {
|
||||
@ -618,3 +624,7 @@ final class MPVBackend: PlayerBackend {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Notification.Name {
|
||||
static let getTimeUpdatesNotification = Notification.Name("getTimeUpdatesNotification")
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user