mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 00:08:21 +00:00
highlight current chapter when clicked on it
This commit is contained in:
parent
7de702ad23
commit
982dca1846
@ -22,6 +22,10 @@ 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
|
||||||
@ -30,13 +34,7 @@ import SwiftUI
|
|||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
.onReceive(PlayerTimeModel.shared.$currentTime) { cmTime in
|
.onReceive(PlayerTimeModel.shared.$currentTime) { cmTime in
|
||||||
let time = CMTimeGetSeconds(cmTime)
|
self.handleTimeUpdate(cmTime)
|
||||||
if time >= self.chapter.start, self.nextChapterStart == nil || time < self.nextChapterStart! {
|
|
||||||
player.currentChapterIndex = self.chapterIndex
|
|
||||||
if !player.playedChapters.contains(self.chapterIndex) {
|
|
||||||
player.playedChapters.append(self.chapterIndex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +48,7 @@ import SwiftUI
|
|||||||
.lineLimit(3)
|
.lineLimit(3)
|
||||||
.multilineTextAlignment(.leading)
|
.multilineTextAlignment(.leading)
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
.foregroundColor(isCurrentChapter ? .appRed : .primary)
|
.foregroundColor(isCurrentChapter ? Color("AppRedColor") : .primary)
|
||||||
Text(chapter.start.formattedAsPlaybackTime(allowZero: true) ?? "")
|
Text(chapter.start.formattedAsPlaybackTime(allowZero: true) ?? "")
|
||||||
.font(.system(.subheadline).monospacedDigit())
|
.font(.system(.subheadline).monospacedDigit())
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
@ -78,6 +76,16 @@ import SwiftUI
|
|||||||
static var thumbnailHeight: Double {
|
static var thumbnailHeight: Double {
|
||||||
thumbnailWidth / 1.7777
|
thumbnailWidth / 1.7777
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user