Update Music Player

This commit is contained in:
Hariharan Mudaliar 2026-03-04 20:04:38 +05:30
commit ccd0732294
No known key found for this signature in database
GPG key ID: 025583EB0BE5640E
3 changed files with 30 additions and 3 deletions

View file

@ -365,7 +365,7 @@ struct LockScreenMusicPanel: View {
private var progressBar: some View { private var progressBar: some View {
TimelineView( TimelineView(
.animation( .animation(
minimumInterval: 0.1, minimumInterval: 1.0,
paused: isProgressTimelinePaused paused: isProgressTimelinePaused
) )
) { timeline in ) { timeline in

View file

@ -654,10 +654,16 @@ private struct MinimalisticReminderDetailsView: View {
@State private var dragging: Bool = false @State private var dragging: Bool = false
@State private var lastDragged: Date = .distantPast @State private var lastDragged: Date = .distantPast
/// Whether the progress timeline should be paused (no ticks).
private var isProgressTimelinePaused: Bool {
!musicManager.isPlaying || musicManager.isLiveStream || musicManager.playbackRate <= 0
}
private var progressBar: some View { private var progressBar: some View {
TimelineView( TimelineView(
.animation( .animation(
minimumInterval: (!musicManager.isLiveStream && musicManager.playbackRate > 0) ? 0.1 : nil minimumInterval: 1.0,
paused: isProgressTimelinePaused
) )
) { timeline in ) { timeline in
MusicSliderView( MusicSliderView(

View file

@ -215,8 +215,13 @@ struct MusicControlsView: View {
} }
} }
/// Whether the progress timeline should be paused (no ticks).
private var isProgressTimelinePaused: Bool {
!musicManager.isPlaying || musicManager.isLiveStream || musicManager.playbackRate <= 0
}
private var musicSlider: some View { private var musicSlider: some View {
TimelineView(.animation(minimumInterval: musicManager.playbackRate > 0 ? 0.1 : nil)) { timeline in TimelineView(.animation(minimumInterval: 1.0, paused: isProgressTimelinePaused)) { timeline in
MusicSliderView( MusicSliderView(
sliderValue: $sliderValue, sliderValue: $sliderValue,
duration: $musicManager.songDuration, duration: $musicManager.songDuration,
@ -639,6 +644,13 @@ struct MusicSliderView: View {
guard !dragging, timestampDate.timeIntervalSince(lastDragged) > -1 else { return } guard !dragging, timestampDate.timeIntervalSince(lastDragged) > -1 else { return }
sliderValue = MusicManager.shared.estimatedPlaybackPosition(at: newDate) sliderValue = MusicManager.shared.estimatedPlaybackPosition(at: newDate)
} }
.onChange(of: isPlaying) { _, playing in
// Snap slider to the exact position when music pauses so
// the in-flight animation doesn't coast past the true value.
if !playing {
sliderValue = MusicManager.shared.estimatedPlaybackPosition()
}
}
.onChange(of: isLiveStream) { isLive in .onChange(of: isLiveStream) { isLive in
if isLive { if isLive {
sliderValue = 0 sliderValue = 0
@ -711,6 +723,15 @@ struct MusicSliderView: View {
restingTrackHeight: restingTrackHeight, restingTrackHeight: restingTrackHeight,
draggingTrackHeight: draggingTrackHeight draggingTrackHeight: draggingTrackHeight
) )
// Smoothly interpolate the filled track between 1-second ticks using
// Core Animation — runs on the GPU with zero CPU polling cost.
// Disabled while dragging or paused so the bar responds instantly.
.animation(
!dragging && isPlaying && !isLiveStream
? .linear(duration: 1.0)
: nil,
value: sliderValue
)
} }
private var sliderTint: Color { private var sliderTint: Color {