feat: add streaming buffer progress indicator to seekbar
Show a subtle buffer progress bar in the seekbar when streaming tracks (before they are fully cached). The bar disappears once the track is fully buffered. Backend: expose buffer_progress from BufferedMediaSource through SharedState -> PlaybackEvent -> playerStore. Frontend: render .seekbar-buffer bar behind the playback fill. cc
This commit is contained in:
6 files changed
+61
-1
No files matched your search
@@ -602,6 +602,8 @@ pub struct SharedState {
|
||||
gapless_ready: Arc<AtomicBool>,
|
||||
/// Track ID of the gapless-queued next track (0 = none)
|
||||
gapless_next_track_id: Arc<AtomicU64>,
|
||||
/// Streaming buffer progress (0.0-1.0 stored as f32 bits, 0 = not streaming)
|
||||
buffer_progress: Arc<AtomicU32>,
|
||||
}
|
||||
|
||||
impl Default for SharedState {
|
||||
@@ -628,6 +630,7 @@ impl SharedState {
|
||||
normalization_gain: Arc::new(AtomicU32::new(0)),
|
||||
gapless_ready: Arc::new(AtomicBool::new(false)),
|
||||
gapless_next_track_id: Arc::new(AtomicU64::new(0)),
|
||||
buffer_progress: Arc::new(AtomicU32::new(0)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -671,6 +674,23 @@ impl SharedState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set streaming buffer progress (0.0 to 1.0). Pass 0.0 when not streaming.
|
||||
pub fn set_buffer_progress(&self, progress: f32) {
|
||||
self.buffer_progress
|
||||
.store(progress.to_bits(), Ordering::SeqCst);
|
||||
}
|
||||
|
||||
/// Get streaming buffer progress (0.0 to 1.0). Returns None if not streaming.
|
||||
pub fn get_buffer_progress(&self) -> Option<f32> {
|
||||
let bits = self.buffer_progress.load(Ordering::SeqCst);
|
||||
let progress = f32::from_bits(bits);
|
||||
if progress <= 0.0 || progress >= 1.0 {
|
||||
None
|
||||
} else {
|
||||
Some(progress)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_current_device(&self, device: Option<String>) {
|
||||
if let Ok(mut d) = self.current_device.write() {
|
||||
*d = device;
|
||||
@@ -2314,6 +2334,14 @@ impl Player {
|
||||
if now.duration_since(last_empty_check) >= Duration::from_millis(500) {
|
||||
last_empty_check = now;
|
||||
|
||||
// Update streaming buffer progress for UI seekbar
|
||||
if let Some(streaming_src) = current_streaming_source.as_ref() {
|
||||
let progress = streaming_src.progress().unwrap_or(1.0);
|
||||
thread_state.set_buffer_progress(progress);
|
||||
} else {
|
||||
thread_state.set_buffer_progress(0.0);
|
||||
}
|
||||
|
||||
// Streaming -> cached promotion:
|
||||
// once streaming download completes, persist full data and clear streaming marker.
|
||||
// This unlocks normal gapless pre-queue for the current track's tail.
|
||||
|
||||
@@ -911,6 +911,7 @@ pub fn run() {
|
||||
normalization_gain,
|
||||
gapless_ready,
|
||||
gapless_next_track_id,
|
||||
buffer_progress,
|
||||
) = if let Some(ref v2_state) = v2_state_opt {
|
||||
let v2_track_id = v2_state.current_track_id();
|
||||
if v2_track_id != 0 {
|
||||
@@ -926,6 +927,7 @@ pub fn run() {
|
||||
v2_state.get_normalization_gain(),
|
||||
v2_state.is_gapless_ready(),
|
||||
v2_state.get_gapless_next_track_id(),
|
||||
v2_state.get_buffer_progress(),
|
||||
)
|
||||
} else {
|
||||
// Fallback to legacy player
|
||||
@@ -940,6 +942,7 @@ pub fn run() {
|
||||
legacy_player_state.get_normalization_gain(),
|
||||
legacy_player_state.is_gapless_ready(),
|
||||
legacy_player_state.get_gapless_next_track_id(),
|
||||
None,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@@ -955,6 +958,7 @@ pub fn run() {
|
||||
legacy_player_state.get_normalization_gain(),
|
||||
legacy_player_state.is_gapless_ready(),
|
||||
legacy_player_state.get_gapless_next_track_id(),
|
||||
None,
|
||||
)
|
||||
};
|
||||
|
||||
@@ -999,6 +1003,7 @@ pub fn run() {
|
||||
normalization_gain,
|
||||
gapless_ready,
|
||||
gapless_next_track_id,
|
||||
buffer_progress,
|
||||
};
|
||||
let _ = app_handle.emit("playback:state", &event);
|
||||
api_server::broadcast_playback_event(&app_handle, &event);
|
||||
|
||||
@@ -580,6 +580,9 @@ pub struct PlaybackEvent {
|
||||
/// Track ID of the gapless-queued next track (0 = none queued)
|
||||
#[serde(default)]
|
||||
pub gapless_next_track_id: u64,
|
||||
/// Streaming buffer progress (0.0-1.0), None when fully cached
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub buffer_progress: Option<f32>,
|
||||
}
|
||||
|
||||
/// Shared state between main thread and audio thread
|
||||
@@ -2776,6 +2779,7 @@ impl Player {
|
||||
normalization_gain: self.state.get_normalization_gain(),
|
||||
gapless_ready: self.state.is_gapless_ready(),
|
||||
gapless_next_track_id: self.state.get_gapless_next_track_id(),
|
||||
buffer_progress: None, // Legacy player doesn't track streaming buffer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@
|
||||
qconnectBusy?: boolean;
|
||||
showQconnectDevButton?: boolean;
|
||||
volumeLocked?: boolean;
|
||||
bufferProgress?: number | null;
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -145,6 +146,7 @@
|
||||
qconnectBusy = false,
|
||||
showQconnectDevButton = false,
|
||||
volumeLocked = false,
|
||||
bufferProgress = null,
|
||||
}: Props = $props();
|
||||
|
||||
let progressRef = $state<HTMLDivElement | null>(null);
|
||||
@@ -274,6 +276,9 @@
|
||||
aria-valuemax={duration}
|
||||
>
|
||||
<div class="seekbar-track">
|
||||
{#if bufferProgress != null && bufferProgress < 1}
|
||||
<div class="seekbar-buffer" style="width: {bufferProgress * 100}%"></div>
|
||||
{/if}
|
||||
<div class="seekbar-fill" style="width: {progress}%"></div>
|
||||
</div>
|
||||
<div class="seekbar-thumb" style="left: {progress}%"></div>
|
||||
@@ -662,6 +667,7 @@
|
||||
}
|
||||
|
||||
.seekbar-track {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 3px;
|
||||
background: var(--border-subtle);
|
||||
@@ -669,7 +675,17 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.seekbar-buffer {
|
||||
position: absolute;
|
||||
height: 100%;
|
||||
background: var(--text-muted, #666);
|
||||
opacity: 0.3;
|
||||
border-radius: 999px;
|
||||
transition: width 250ms linear;
|
||||
}
|
||||
|
||||
.seekbar-fill {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
background: var(--accent-primary, #6366f1);
|
||||
border-radius: 999px;
|
||||
|
||||
@@ -144,6 +144,7 @@ let isAdvancingTrack = false;
|
||||
let isSkipping = false;
|
||||
let queueEnded = false;
|
||||
let normalizationGain: number | null = null; // Current normalization gain (null = not active)
|
||||
let bufferProgress: number | null = null; // Streaming buffer progress (0-1, null = fully cached)
|
||||
let pendingSeekPosition: number | null = null;
|
||||
let seekRequestInFlight = false;
|
||||
let seekTargetPosition: number | null = null;
|
||||
@@ -257,6 +258,7 @@ export interface PlayerState {
|
||||
isFavorite: boolean;
|
||||
isSkipping: boolean;
|
||||
normalizationGain: number | null;
|
||||
bufferProgress: number | null;
|
||||
}
|
||||
|
||||
export function getPlayerState(): PlayerState {
|
||||
@@ -268,7 +270,8 @@ export function getPlayerState(): PlayerState {
|
||||
volume,
|
||||
isFavorite,
|
||||
isSkipping,
|
||||
normalizationGain
|
||||
normalizationGain,
|
||||
bufferProgress
|
||||
};
|
||||
}
|
||||
|
||||
@@ -764,6 +767,7 @@ async function handlePlaybackEvent(event: PlaybackEvent): Promise<void> {
|
||||
|
||||
// Update normalization gain state
|
||||
normalizationGain = event.normalization_gain;
|
||||
bufferProgress = event.buffer_progress ?? null;
|
||||
|
||||
notifyListeners();
|
||||
|
||||
|
||||
@@ -910,6 +910,7 @@
|
||||
let isFavorite = $state(false);
|
||||
let normalizationEnabled = $state(false);
|
||||
let normalizationGain = $state<number | null>(null);
|
||||
let bufferProgress = $state<number | null>(null);
|
||||
let isAlsaDirectHw = $state(false); // ALSA Direct hw: locks volume to 100%
|
||||
// Queue/Shuffle State (from queueStore subscription)
|
||||
let isShuffle = $state(false);
|
||||
@@ -4189,6 +4190,7 @@
|
||||
const wasPlaying = isPlaying;
|
||||
volume = playerState.volume;
|
||||
normalizationGain = playerState.normalizationGain;
|
||||
bufferProgress = playerState.bufferProgress;
|
||||
if (remotePeerActive) {
|
||||
return;
|
||||
}
|
||||
@@ -5667,6 +5669,7 @@
|
||||
qconnectBusy={qobuzConnectBusy}
|
||||
{showQconnectDevButton}
|
||||
volumeLocked={isAlsaDirectHw && !qconnectPeerRendererActive}
|
||||
{bufferProgress}
|
||||
/>
|
||||
{:else}
|
||||
<NowPlayingBar
|
||||
|
||||
Reference in new issue
Block a user