TrackHandle: add metadata field (#25)
* Adds metadata field to TrackHandle. Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use super::*;
|
||||
use crate::events::{Event, EventData, EventHandler};
|
||||
use std::time::Duration;
|
||||
use crate::{
|
||||
events::{Event, EventData, EventHandler},
|
||||
input::Metadata,
|
||||
};
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use tokio::sync::{
|
||||
mpsc::{error::SendError, UnboundedSender},
|
||||
oneshot,
|
||||
@@ -20,6 +23,7 @@ pub struct TrackHandle {
|
||||
command_channel: UnboundedSender<TrackCommand>,
|
||||
seekable: bool,
|
||||
uuid: Uuid,
|
||||
metadata: Arc<Metadata>,
|
||||
}
|
||||
|
||||
impl TrackHandle {
|
||||
@@ -27,11 +31,17 @@ impl TrackHandle {
|
||||
/// the underlying [`Input`] supports seek operations.
|
||||
///
|
||||
/// [`Input`]: crate::input::Input
|
||||
pub fn new(command_channel: UnboundedSender<TrackCommand>, seekable: bool, uuid: Uuid) -> Self {
|
||||
pub fn new(
|
||||
command_channel: UnboundedSender<TrackCommand>,
|
||||
seekable: bool,
|
||||
uuid: Uuid,
|
||||
metadata: Metadata,
|
||||
) -> Self {
|
||||
Self {
|
||||
command_channel,
|
||||
seekable,
|
||||
uuid,
|
||||
metadata: Arc::new(metadata),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +167,17 @@ impl TrackHandle {
|
||||
self.uuid
|
||||
}
|
||||
|
||||
/// Returns the metadata stored in the handle.
|
||||
///
|
||||
/// Metadata is cloned from the inner [`Input`] at
|
||||
/// the time a track/handle is created, and is effectively
|
||||
/// read-only from then on.
|
||||
///
|
||||
/// [`Input`]: crate::input::Input
|
||||
pub fn metadata(&self) -> Arc<Metadata> {
|
||||
self.metadata.clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Send a raw command to the [`Track`] object.
|
||||
///
|
||||
|
||||
@@ -366,7 +366,8 @@ impl Track {
|
||||
pub fn create_player(source: Input) -> (Track, TrackHandle) {
|
||||
let (tx, rx) = mpsc::unbounded_channel();
|
||||
let can_seek = source.is_seekable();
|
||||
let handle = TrackHandle::new(tx, can_seek, Uuid::new_v4());
|
||||
let metadata = source.metadata.clone();
|
||||
let handle = TrackHandle::new(tx, can_seek, Uuid::new_v4(), metadata);
|
||||
|
||||
let player = Track::new_raw(source, rx, handle.clone());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user