[][src]Struct serenity::voice::Audio

pub struct Audio {
    pub playing: bool,
    pub volume: f32,
    pub finished: bool,
    pub source: Box<dyn AudioSource>,
    pub position: Duration,
    pub position_modified: bool,
}

Control object for audio playback.

Accessed by both commands and the playback code -- as such, access is always guarded. In particular, you should expect to receive a LockedAudio when calling Handler::play_returning or Handler::play_only.

Example

This example is not tested
use serenity::voice::{Handler, LockedAudio, ffmpeg};

let handler: Handler = /* ... */;
let source = ffmpeg("../audio/my-favourite-song.mp3")?;
let safe_audio: LockedAudio = handler.play_only(source);
{
    let audio_lock = safe_audio_control.clone();
    let mut audio = audio_lock.lock().await;

    audio.volume(0.5);
}

Fields

playing: bool

Whether or not this sound is currently playing.

Can be controlled with play or pause if chaining is desired.

volume: f32

The desired volume for playback.

Sensible values fall between 0.0 and 1.0.

Can be controlled with volume if chaining is desired.

finished: bool

Whether or not the sound has finished, or reached the end of its stream.

Read-only for now.

source: Box<dyn AudioSource>

Underlying data access object.

Calling code is not expected to use this.

position: Duration

The current position for playback.

Consider the position fields read-only for now.

position_modified: bool

Implementations

impl Audio[src]

pub fn new(source: Box<dyn AudioSource>) -> Self[src]

pub fn play(&mut self) -> &mut Self[src]

Sets playing to true in a manner that allows method chaining.

pub fn pause(&mut self) -> &mut Self[src]

Sets playing to false in a manner that allows method chaining.

pub fn volume(&mut self, volume: f32) -> &mut Self[src]

Sets volume in a manner that allows method chaining.

pub fn position(&mut self, position: Duration) -> &mut Self[src]

Change the position in the stream for subsequent playback.

Currently a No-op.

Auto Trait Implementations

impl !RefUnwindSafe for Audio

impl Send for Audio

impl Sync for Audio

impl Unpin for Audio

impl !UnwindSafe for Audio

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

impl<T> WithSubscriber for T[src]