mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-28 07:34:32 +00:00
commit
a3c74bbde3
2 changed files with 24 additions and 3 deletions
|
|
@ -97,6 +97,7 @@ struct AlbumArtView: View {
|
||||||
|
|
||||||
struct MusicControlsView: View {
|
struct MusicControlsView: View {
|
||||||
@ObservedObject var musicManager = MusicManager.shared
|
@ObservedObject var musicManager = MusicManager.shared
|
||||||
|
@EnvironmentObject var vm: DynamicIslandViewModel
|
||||||
@State private var sliderValue: Double = 0
|
@State private var sliderValue: Double = 0
|
||||||
@State private var dragging: Bool = false
|
@State private var dragging: Bool = false
|
||||||
@State private var lastDragged: Date = .distantPast
|
@State private var lastDragged: Date = .distantPast
|
||||||
|
|
@ -108,6 +109,16 @@ struct MusicControlsView: View {
|
||||||
}
|
}
|
||||||
.buttonStyle(PlainButtonStyle())
|
.buttonStyle(PlainButtonStyle())
|
||||||
.frame(minWidth: Defaults[.showMirror] && Defaults[.showCalendar] ? 140 : 180)
|
.frame(minWidth: Defaults[.showMirror] && Defaults[.showCalendar] ? 140 : 180)
|
||||||
|
.onAppear {
|
||||||
|
// Initialize slider value when view appears
|
||||||
|
sliderValue = musicManager.elapsedTime
|
||||||
|
}
|
||||||
|
.onChange(of: vm.notchState) { _, newState in
|
||||||
|
// Reset slider value when notch opens to prevent stuck state
|
||||||
|
if newState == .open && !dragging {
|
||||||
|
sliderValue = musicManager.elapsedTime
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var songInfoAndSlider: some View {
|
private var songInfoAndSlider: some View {
|
||||||
|
|
@ -137,7 +148,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,
|
||||||
|
|
@ -278,7 +289,7 @@ struct MusicSliderView: View {
|
||||||
|
|
||||||
var currentElapsedTime: Double {
|
var currentElapsedTime: Double {
|
||||||
// A small buffer is needed to ensure a meaningful difference between the two dates
|
// A small buffer is needed to ensure a meaningful difference between the two dates
|
||||||
guard !dragging, timestampDate.timeIntervalSince(lastDragged) > -0.0001, (timestampDate > lastUpdated || ignoreLastUpdated) else { return sliderValue }
|
guard !dragging, timestampDate.timeIntervalSince(lastDragged) > -1 else { return sliderValue }
|
||||||
let timeDifference = isPlaying ? currentDate.timeIntervalSince(timestampDate) : 0
|
let timeDifference = isPlaying ? currentDate.timeIntervalSince(timestampDate) : 0
|
||||||
let elapsed = elapsedTime + (timeDifference * playbackRate)
|
let elapsed = elapsedTime + (timeDifference * playbackRate)
|
||||||
return min(elapsed, duration)
|
return min(elapsed, duration)
|
||||||
|
|
|
||||||
|
|
@ -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