1pub fn playback_icon(state: &sonos_sdk::PlaybackState) -> &'static str {
3 match state {
4 sonos_sdk::PlaybackState::Playing => "\u{25b6}",
5 sonos_sdk::PlaybackState::Paused => "\u{23f8}",
6 _ => "\u{25a0}",
7 }
8}
9
10pub fn playback_label(state: &sonos_sdk::PlaybackState) -> &'static str {
12 match state {
13 sonos_sdk::PlaybackState::Playing => "Playing",
14 sonos_sdk::PlaybackState::Paused => "Paused",
15 sonos_sdk::PlaybackState::Stopped => "Stopped",
16 sonos_sdk::PlaybackState::Transitioning => "Transitioning",
17 }
18}
19
20pub fn format_time_ms(ms: u64) -> String {
22 let total_secs = ms / 1000;
23 let hours = total_secs / 3600;
24 let minutes = (total_secs % 3600) / 60;
25 let seconds = total_secs % 60;
26 if hours > 0 {
27 format!("{hours}:{minutes:02}:{seconds:02}")
28 } else {
29 format!("{minutes}:{seconds:02}")
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn format_time_ms_values() {
39 assert_eq!(format_time_ms(0), "0:00");
40 assert_eq!(format_time_ms(151_000), "2:31");
41 assert_eq!(format_time_ms(355_000), "5:55");
42 assert_eq!(format_time_ms(3_661_000), "1:01:01");
43 }
44}