MCPcopy Create free account
hub / github.com/DioxusLabs/dioxus-components / BlockPlayer

Function BlockPlayer

preview/src/main.rs:1416–1513  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1414
1415#[component]
1416fn BlockPlayer() -> Element {
1417 const TRACK_DURATION_SECONDS: f64 = 212.0;
1418 const TRACK_START_SECONDS: f64 = 84.0;
1419
1420 let mut playing = use_signal(|| true);
1421 let mut progress_seconds = use_signal(|| Some(TRACK_START_SECONDS));
1422 let current_time = use_memo(move || format_track_time(progress_seconds().unwrap_or(0.0)));
1423 let duration_time = format_track_time(TRACK_DURATION_SECONDS);
1424
1425 use_effect(move || {
1426 let mut timer = document::eval(
1427 "setInterval(() => {
1428 dioxus.send(performance.now());
1429 }, 100);",
1430 );
1431
1432 spawn(async move {
1433 let mut last_tick_ms: Option<f64> = None;
1434
1435 while let Ok(now_ms) = timer.recv::<f64>().await {
1436 let elapsed_seconds = last_tick_ms
1437 .map(|last_ms| ((now_ms - last_ms) / 1000.0).clamp(0.0, 0.25))
1438 .unwrap_or(0.0);
1439 last_tick_ms = Some(now_ms);
1440
1441 if !playing() {
1442 continue;
1443 }
1444
1445 let current = progress_seconds().unwrap_or(0.0);
1446 let next = if current >= TRACK_DURATION_SECONDS {
1447 0.0
1448 } else {
1449 (current + elapsed_seconds).min(TRACK_DURATION_SECONDS)
1450 };
1451 progress_seconds.set(Some(next));
1452 }
1453 });
1454 });
1455
1456 rsx! {
1457 div { style: "display: flex; gap: 0.85rem; align-items: center;",
1458 img {
1459 src: "https://avatar.vercel.sh/midnight-city",
1460 alt: "Midnight City album art",
1461 width: "64",
1462 height: "64",
1463 style: "width: 64px; height: 64px; border-radius: 0.45rem; object-fit: cover; flex-shrink: 0; box-shadow: 0 6px 18px -8px rgba(0,0,0,0.35);",
1464 }
1465 div { style: "flex: 1; min-width: 0;",
1466 p { style: "margin: 0; font-weight: 600; color: var(--secondary-color-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;",
1467 "Midnight City"
1468 }
1469 p { style: "margin: 0.15rem 0 0; color: var(--secondary-color-5); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;",
1470 "M83 · Hurry Up, We're Dreaming"
1471 }
1472 }
1473 }

Callers

nothing calls this directly

Calls 2

format_track_timeFunction · 0.85
clampMethod · 0.80

Tested by

no test coverage detected