diff options
| author | Yuval Adam <_@yuv.al> | 2024-06-04 20:50:46 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2024-06-04 20:50:46 +0200 |
| commit | 355743d349d8f63a5d98246c0f0265812fbb2482 (patch) | |
| tree | c48c313ebad2949afa96e64d8ed48e1d2b16fdf7 /src/audio | |
| parent | 482a942cd9e62fadee4ee7bc1fd7e8def8a85f71 (diff) | |
Initial spinner mpsc
Diffstat (limited to 'src/audio')
| -rw-r--r-- | src/audio/mod.rs | 8 | ||||
| -rw-r--r-- | src/audio/mpv.rs | 3 | ||||
| -rw-r--r-- | src/audio/rodio.rs | 7 |
3 files changed, 11 insertions, 7 deletions
diff --git a/src/audio/mod.rs b/src/audio/mod.rs index 5aae19a..81cdc70 100644 --- a/src/audio/mod.rs +++ b/src/audio/mod.rs @@ -1,3 +1,5 @@ +use tokio::sync::mpsc; + mod mpv; mod rodio; @@ -13,10 +15,10 @@ pub fn get_backend() -> AudioBackends { } impl AudioBackends { - pub async fn play(&self, url: &str) { + pub async fn play(&self, url: &str, tx: mpsc::Sender<String>) { match self { - AudioBackends::Mpv(m) => m.play(url).await, - AudioBackends::Rodio(r) => r.play(url).await, + AudioBackends::Mpv(m) => m.play(url, tx).await, + AudioBackends::Rodio(r) => r.play(url, tx).await, } } } diff --git a/src/audio/mpv.rs b/src/audio/mpv.rs index fde2711..06d3630 100644 --- a/src/audio/mpv.rs +++ b/src/audio/mpv.rs @@ -1,9 +1,10 @@ use std::process::Command; +use tokio::sync::mpsc; pub struct Mpv {} impl Mpv { - pub async fn play(&self, url: &str) { + pub async fn play(&self, url: &str, _tx: mpsc::Sender<String>) { Command::new("mpv") .args([url]) .output() diff --git a/src/audio/rodio.rs b/src/audio/rodio.rs index 0f9fbb2..695c6cb 100644 --- a/src/audio/rodio.rs +++ b/src/audio/rodio.rs @@ -6,13 +6,14 @@ use stream_download::http::HttpStream; use stream_download::storage::bounded::BoundedStorageProvider; use stream_download::storage::memory::MemoryStorageProvider; use stream_download::{Settings, StreamDownload}; +use tokio::sync::mpsc; const AUDIO_BUFFER_SECONDS: u32 = 5; pub struct Rodio {} impl Rodio { - pub async fn play(&self, url: &str) { + pub async fn play(&self, url: &str, tx: mpsc::Sender<String>) { let (_stream, handle) = OutputStream::try_default().unwrap(); let sink = Sink::try_new(&handle).unwrap(); @@ -48,10 +49,10 @@ impl Rodio { // Since we requested icy metadata, the metadata interval header should be present in the // response. This will allow us to parse the metadata within the stream icy_headers.metadata_interval(), - |metadata| { + move |metadata| { if let Ok(md) = metadata { if let Some(tr) = md.stream_title() { - println!(" {tr}"); + let _ = tx.send(tr.to_string()); } } }, |
