Struct Track

Source
pub struct Track {
    pub playing: PlayMode,
    pub volume: f32,
    pub input: Input,
    pub events: EventStore,
    pub loops: LoopState,
    pub uuid: Uuid,
    pub user_data: Arc<dyn Any + Send + Sync>,
}
Expand description

Initial state for audio playback.

Tracks allow you to configure play modes, volume, event handlers, and other track state before you pass an input to the Driver.

Live track data is accessed via a TrackHandle, which is returned by Driver::play and related methods.

§Example

use songbird::{driver::Driver, input::File, tracks::Track};

// A Call is also valid here!
let mut driver: Driver = Default::default();
let source = File::new("../audio/my-favourite-song.mp3");

let handle = driver.play_only(Track::from(source).volume(0.5));

// Future access occurs via audio.

Fields§

§playing: PlayMode

Whether or not this sound is currently playing.

Defaults to PlayMode::Play.

§volume: f32

The volume for playback.

Sensible values fall between 0.0 and 1.0. Values outside this range can cause clipping or other audio artefacts.

Defaults to 1.0.

§input: Input

The live or lazily-initialised audio stream to be played.

§events: EventStore

List of events attached to this audio track.

This may be used to add additional events to a track before it is sent to the audio context for playing.

Defaults to an empty set.

§loops: LoopState

Count of remaining loops.

Defaults to play a track once (i.e., LoopState::Finite(0)).

§uuid: Uuid

Unique identifier for this track.

Defaults to a random 128-bit number.

§user_data: Arc<dyn Any + Send + Sync>

Any data to be associated with the track.

Implementations§

Source§

impl Track

Source

pub fn new(input: Input) -> Self

Create a new track directly from an Input and a random Uuid.

Source

pub fn new_with_uuid(input: Input, uuid: Uuid) -> Self

Create a new track directly from an Input with a custom Uuid.

Source

pub fn new_with_data( input: Input, user_data: Arc<dyn Any + Send + Sync + 'static>, ) -> Self

Create a new track directly from an Input, user data to be associated with the track, and a random Uuid.

Source

pub fn new_with_uuid_and_data( input: Input, uuid: Uuid, user_data: Arc<dyn Any + Send + Sync + 'static>, ) -> Self

Create a new track directly from an Input, user data to be associated with the track, and a custom Uuid.

Source

pub fn play(self) -> Self

Sets a track to playing if it is paused.

Source

pub fn pause(self) -> Self

Pre-emptively pauses a track, preventing it from being automatically played.

Source

pub fn stop(self) -> Self

Manually stops a track.

This will cause the audio track to be removed by the driver almost immediately, with any relevant events triggered.

Source

pub fn volume(self, volume: f32) -> Self

Sets volume in a manner that allows method chaining.

Source

pub fn loops(self, loops: LoopState) -> Self

Set an audio track to loop a set number of times.

Source

pub fn uuid(self, uuid: Uuid) -> Self

Returns this track’s unique identifier.

Trait Implementations§

Source§

impl<T: Into<Input>> From<T> for Track

Any Input (or struct which can be used as one) can also be made into a Track.

Source§

fn from(val: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Track

§

impl !RefUnwindSafe for Track

§

impl Send for Track

§

impl !Sync for Track

§

impl Unpin for Track

§

impl !UnwindSafe for Track

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T