mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Update Music Player
This commit is contained in:
parent
1441f83388
commit
ccd0732294
3 changed files with 30 additions and 3 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue