From d00e59c091d7497290af1b92c169826dd6aa5fea Mon Sep 17 00:00:00 2001 From: Vaporox Date: Mon, 7 Mar 2022 21:19:12 +0100 Subject: [PATCH] feat: return track handle when adding an `Input` to the queue --- src/driver/mod.rs | 9 +++++---- src/tracks/queue.rs | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/driver/mod.rs b/src/driver/mod.rs index 3d78eab80..4210b94c5 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -281,10 +281,11 @@ impl Driver { /// Requires the `"builtin-queue"` feature. /// /// [`Input`]: crate::input::Input - pub fn enqueue_source(&mut self, source: Input) { - let (mut track, _) = tracks::create_player(source); - self.queue.add_raw(&mut track); - self.play(track); + pub fn enqueue_source(&mut self, source: Input) -> TrackHandle { + let (track, handle) = tracks::create_player(source); + self.enqueue(track); + + handle } /// Adds an existing [`Track`] to this driver's built-in queue. diff --git a/src/tracks/queue.rs b/src/tracks/queue.rs index 053848bb7..0ad6bf53f 100644 --- a/src/tracks/queue.rs +++ b/src/tracks/queue.rs @@ -165,9 +165,11 @@ impl TrackQueue { } /// Adds an audio source to the queue, to be played in the channel managed by `handler`. - pub fn add_source(&self, source: Input, handler: &mut Driver) { - let (audio, _) = tracks::create_player(source); - self.add(audio, handler); + pub fn add_source(&self, source: Input, handler: &mut Driver) -> TrackHandle { + let (track, handle) = tracks::create_player(source); + self.add(track, handler); + + handle } /// Adds a [`Track`] object to the queue, to be played in the channel managed by `handler`.