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 super::*;
|
||||||
use crate::events::{Event, EventData, EventHandler};
|
use crate::{
|
||||||
use std::time::Duration;
|
events::{Event, EventData, EventHandler},
|
||||||
|
input::Metadata,
|
||||||
|
};
|
||||||
|
use std::{sync::Arc, time::Duration};
|
||||||
use tokio::sync::{
|
use tokio::sync::{
|
||||||
mpsc::{error::SendError, UnboundedSender},
|
mpsc::{error::SendError, UnboundedSender},
|
||||||
oneshot,
|
oneshot,
|
||||||
@@ -20,6 +23,7 @@ pub struct TrackHandle {
|
|||||||
command_channel: UnboundedSender<TrackCommand>,
|
command_channel: UnboundedSender<TrackCommand>,
|
||||||
seekable: bool,
|
seekable: bool,
|
||||||
uuid: Uuid,
|
uuid: Uuid,
|
||||||
|
metadata: Arc<Metadata>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TrackHandle {
|
impl TrackHandle {
|
||||||
@@ -27,11 +31,17 @@ impl TrackHandle {
|
|||||||
/// the underlying [`Input`] supports seek operations.
|
/// the underlying [`Input`] supports seek operations.
|
||||||
///
|
///
|
||||||
/// [`Input`]: crate::input::Input
|
/// [`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 {
|
Self {
|
||||||
command_channel,
|
command_channel,
|
||||||
seekable,
|
seekable,
|
||||||
uuid,
|
uuid,
|
||||||
|
metadata: Arc::new(metadata),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +167,17 @@ impl TrackHandle {
|
|||||||
self.uuid
|
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]
|
#[inline]
|
||||||
/// Send a raw command to the [`Track`] object.
|
/// Send a raw command to the [`Track`] object.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -366,7 +366,8 @@ impl Track {
|
|||||||
pub fn create_player(source: Input) -> (Track, TrackHandle) {
|
pub fn create_player(source: Input) -> (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 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());
|
let player = Track::new_raw(source, rx, handle.clone());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user