pub struct MixMusic<'device> { /* private fields */ }
Expand description

A music buffer of the audio data.

Implementations§

source§

impl<'device> MixMusic<'device>

source

pub fn new( _device: &'device MixDevice<'device>, file_name: &str ) -> Result<Self>

Constructs a music from the file, or Err on failure.

§Panics

Panics if file_name is empty.

source

pub fn music_type(&self) -> MusicType

Returns the type of the music.

source

pub fn with_cmd( device: &'device MixDevice<'device>, file_name: &str, command: &str ) -> Result<Self>

Constructs a music from the file with the custom player command, or Err on failure.

The command must handle the signals emitted by the SDL2_mixer:

  • On stop: SIGTERM signal
  • On pause: SIGSTOP signal
  • On unpause: SIGCONT signal
§Panics

Panics if file_name or command is empty.

source

pub fn play(&self, loops: Option<u32>) -> Result<()>

Plays the music. If a music is already playing, it synchronously waits until the music ends. If loops is None, the play continues infinitely.

source

pub fn fade_in( &self, fade_in: u32, loops: Option<u32>, begin: Option<f64> ) -> Result<()>

Plays the music with fade-in times in milliseconds and begin times in seconds. If a music is already playing, it synchronously waits until the music ends. If loops is None, the play continues infinitely. If begin is None, the play begins from the start.

source

pub fn set_pos(&self, pos: f64) -> Result<()>

Sets the music position in seconds, or Err on failure.

source

pub fn volume(&self) -> u32

Returns the volume of the music.

source

pub fn set_volume(&self, volume: u32)

Sets the volume of the music. The volume is clamped in 0..=128.

source

pub fn rewind(&self)

Rewinds the music to the beginning. Rewinding is valid only mod, ogg vorbis, mpeg-1 layer-3, and midi format.

source

pub fn pause(&'device mut self) -> Pauser<'device>

Pauses the music until dropping the Pauser.

source

pub fn halt(&self)

Halts the music.

source

pub fn fade_out(&self, fade_out: u32) -> Result<()>

Halts the music with fade-out in milliseconds.

source

pub fn is_playing(&self) -> bool

Returns whether the music is playing.

source

pub fn fading_state(&self) -> FadingState

Returns the fading state of the music.

Trait Implementations§

source§

impl Drop for MixMusic<'_>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'device> !RefUnwindSafe for MixMusic<'device>

§

impl<'device> !Send for MixMusic<'device>

§

impl<'device> !Sync for MixMusic<'device>

§

impl<'device> Unpin for MixMusic<'device>

§

impl<'device> !UnwindSafe for MixMusic<'device>

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.

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.