Tracks: Allow custom UUID setting (#33)

This commit is contained in:
baguette
2020-12-30 05:09:44 -05:00
committed by GitHub
parent 03ae0e7628
commit 873458d288
2 changed files with 11 additions and 3 deletions

View File

@@ -24,8 +24,8 @@ pub struct TrackHandle {
struct InnerHandle { struct InnerHandle {
command_channel: UnboundedSender<TrackCommand>, command_channel: UnboundedSender<TrackCommand>,
seekable: bool, seekable: bool,
uuid: Uuid,
metadata: Box<Metadata>, metadata: Box<Metadata>,
uuid: Uuid,
} }
impl TrackHandle { impl TrackHandle {
@@ -42,8 +42,8 @@ impl TrackHandle {
let inner = Arc::new(InnerHandle { let inner = Arc::new(InnerHandle {
command_channel, command_channel,
seekable, seekable,
uuid,
metadata, metadata,
uuid,
}); });
Self { inner } Self { inner }

View File

@@ -377,11 +377,19 @@ impl Track {
/// ///
/// [`Track`]: Track /// [`Track`]: Track
/// [`TrackHandle`]: TrackHandle /// [`TrackHandle`]: TrackHandle
#[inline]
pub fn create_player(source: Input) -> (Track, TrackHandle) { 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 (tx, rx) = mpsc::unbounded_channel();
let can_seek = source.is_seekable(); let can_seek = source.is_seekable();
let metadata = source.metadata.clone(); 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()); let player = Track::new_raw(source, rx, handle.clone());