mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-28 23:54:32 +00:00
Fix: Timeline Playback
This commit is contained in:
parent
1b5925090a
commit
8f770d08f7
2 changed files with 31 additions and 7 deletions
|
|
@ -137,7 +137,7 @@ struct MusicControlsView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private var musicSlider: some View {
|
private var musicSlider: some View {
|
||||||
TimelineView(.animation(minimumInterval: musicManager.playbackRate > 0 ? 0.1 : nil)) { timeline in
|
TimelineView(.animation(minimumInterval: 0.05)) { timeline in
|
||||||
MusicSliderView(
|
MusicSliderView(
|
||||||
sliderValue: $sliderValue,
|
sliderValue: $sliderValue,
|
||||||
duration: $musicManager.songDuration,
|
duration: $musicManager.songDuration,
|
||||||
|
|
@ -277,11 +277,25 @@ struct MusicSliderView: View {
|
||||||
var onValueChange: (Double) -> Void
|
var onValueChange: (Double) -> Void
|
||||||
|
|
||||||
var currentElapsedTime: Double {
|
var currentElapsedTime: Double {
|
||||||
// A small buffer is needed to ensure a meaningful difference between the two dates
|
// Don't update slider while user is dragging
|
||||||
guard !dragging, timestampDate.timeIntervalSince(lastDragged) > -0.0001, (timestampDate > lastUpdated || ignoreLastUpdated) else { return sliderValue }
|
guard !dragging else { return sliderValue }
|
||||||
let timeDifference = isPlaying ? currentDate.timeIntervalSince(timestampDate) : 0
|
|
||||||
let elapsed = elapsedTime + (timeDifference * playbackRate)
|
// If not playing, use the current elapsed time from controller
|
||||||
return min(elapsed, duration)
|
guard isPlaying else { return elapsedTime }
|
||||||
|
|
||||||
|
// For playing media, calculate real-time progress
|
||||||
|
// Use a more permissive approach for web players
|
||||||
|
let timeDiff = currentDate.timeIntervalSince(timestampDate)
|
||||||
|
|
||||||
|
// Only use timestamp calculation if we have recent data (within 5 seconds)
|
||||||
|
// This helps with web players that don't update timestamps frequently
|
||||||
|
if timeDiff >= 0 && timeDiff < 5.0 && playbackRate > 0 {
|
||||||
|
let projectedTime = elapsedTime + (timeDiff * playbackRate)
|
||||||
|
return min(projectedTime, duration)
|
||||||
|
} else {
|
||||||
|
// Fallback to controller-provided elapsed time for stale or invalid timestamps
|
||||||
|
return min(elapsedTime, duration)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,17 @@ class MusicManager: ObservableObject {
|
||||||
self.repeatMode = state.repeatMode
|
self.repeatMode = state.repeatMode
|
||||||
}
|
}
|
||||||
|
|
||||||
self.timestampDate = state.lastUpdated
|
// Update timestamp - use current time if state doesn't provide recent timestamp
|
||||||
|
let stateTimestamp = state.lastUpdated
|
||||||
|
let now = Date()
|
||||||
|
|
||||||
|
// If the state timestamp is very recent (within 1 second), use it
|
||||||
|
// Otherwise, use current time for better real-time calculation
|
||||||
|
if abs(stateTimestamp.timeIntervalSince(now)) < 1.0 {
|
||||||
|
self.timestampDate = stateTimestamp
|
||||||
|
} else {
|
||||||
|
self.timestampDate = now
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the batch update on the main thread
|
// Execute the batch update on the main thread
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue