Skip to content

Commit

Permalink
Tracks: Allow custom UUID setting (serenity-rs#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
peppizza authored Dec 30, 2020
1 parent 03ae0e7 commit 873458d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/tracks/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub struct TrackHandle {
struct InnerHandle {
command_channel: UnboundedSender<TrackCommand>,
seekable: bool,
uuid: Uuid,
metadata: Box<Metadata>,
uuid: Uuid,
}

impl TrackHandle {
Expand All @@ -42,8 +42,8 @@ impl TrackHandle {
let inner = Arc::new(InnerHandle {
command_channel,
seekable,
uuid,
metadata,
uuid,
});

Self { inner }
Expand Down
10 changes: 9 additions & 1 deletion src/tracks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,19 @@ impl Track {
///
/// [`Track`]: Track
/// [`TrackHandle`]: TrackHandle
#[inline]
pub fn create_player(source: Input) -> (Track, TrackHandle) {
create_player_with_uuid(source, Uuid::new_v4())
}

/// Refer to the documentation for [`create_player`] however, allows for a custom uuid to be inserted into the Track and Handle
///
/// [`create_player`]: create_player
pub fn create_player_with_uuid(source: Input, uuid: Uuid) -> (Track, TrackHandle) {
let (tx, rx) = mpsc::unbounded_channel();
let can_seek = source.is_seekable();
let metadata = source.metadata.clone();
let handle = TrackHandle::new(tx, can_seek, Uuid::new_v4(), metadata);
let handle = TrackHandle::new(tx, can_seek, uuid, metadata);

let player = Track::new_raw(source, rx, handle.clone());

Expand Down

0 comments on commit 873458d

Please sign in to comment.