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
|
typealias AreInIncreasingOrder = (Stream, Stream) -> Bool
|
||||||
|
|
||||||
func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream? {
|
func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream? {
|
||||||
@ -432,6 +436,8 @@ final class MPVBackend: PlayerBackend {
|
|||||||
timeObserverThrottle.execute {
|
timeObserverThrottle.execute {
|
||||||
self.model.updateWatch(time: self.currentTime)
|
self.model.updateWatch(time: self.currentTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotificationCenter.default.post(name: .getTimeUpdatesNotification, object: self.currentTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func stopClientUpdates() {
|
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 {
|
var body: some View {
|
||||||
Button(action: {
|
Button(action: {
|
||||||
player.backend.seek(to: chapter.start, seekType: .userInteracted)
|
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 {
|
Group {
|
||||||
verticalChapter
|
verticalChapter
|
||||||
@ -29,9 +25,14 @@ import SwiftUI
|
|||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
.onReceive(PlayerTimeModel.shared.$currentTime) { cmTime in
|
.onReceive(
|
||||||
|
NotificationCenter.default
|
||||||
|
.publisher(for: .getTimeUpdatesNotification)
|
||||||
|
.receive(on: DispatchQueue.main)
|
||||||
|
) { notification in
|
||||||
|
if let cmTime = notification.object as? CMTime {
|
||||||
self.handleTimeUpdate(cmTime)
|
self.handleTimeUpdate(cmTime)
|
||||||
print("currentChapterIndex:", player.currentChapter ?? 0)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user