[go: up one dir, main page]

Music

Struct Music 

Source
pub struct Music<'a> {
    pub raw: *mut Mix_Music,
    pub owned: bool,
    /* private fields */
}
Expand description

This is an opaque data type used for Music data.

Fields§

§raw: *mut Mix_Music§owned: bool

Implementations§

Source§

impl<'a> Music<'a>

Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Music<'static>, String>

Load music file to use.

Source

pub fn from_static_bytes(buf: &'static [u8]) -> Result<Music<'static>, String>

Load music from a static byte buffer.

Source

pub fn get_type(&self) -> MusicType

The file format encoding of the music.

Source

pub fn play(&self, loops: i32) -> Result<(), String>

Play the loaded music loop times through from start to finish. Pass -1 to loop forever.

Source

pub fn fade_in(&self, loops: i32, ms: i32) -> Result<(), String>

Fade in over ms milliseconds of time, the loaded music, playing it loop times through from start to finish.

Source

pub fn fade_in_from_pos( &self, loops: i32, ms: i32, position: f64, ) -> Result<(), String>

Fade in over ms milliseconds of time, from position.

Source

pub fn get_volume() -> i32

Returns current volume

Source

pub fn set_volume(volume: i32)

Set the volume on a scale of 0 to 128. Values greater than 128 will use 128.

Source

pub fn pause()

Pause the music playback.

Source

pub fn resume()

Unpause the music.

Source

pub fn rewind()

Rewind the music to the start.

Source

pub fn set_pos(position: f64) -> Result<(), String>

Set the position of the currently playing music.

Source

pub fn set_command(command: &str) -> Result<(), String>

Setup a command line music player to use to play music.

Source

pub fn halt()

Halt playback of music.

Source

pub fn fade_out(ms: i32) -> Result<(), String>

Gradually fade out the music over ms milliseconds starting from now.

Source

pub fn hook_finished(f: fn())

Sets up a function to be called when music playback is halted.

§Examples
fn after_music() {
    println!("Music has ended");
}

sdl2::mixer::Music::hook_finished(after_music);
Source

pub fn unhook_finished()

A previously set up function would no longer be called when music playback is halted.

Source

pub fn is_playing() -> bool

If music is actively playing, or not.

Source

pub fn is_paused() -> bool

If music is paused, or not.

Source

pub fn get_fading() -> Fading

If music is fading, or not.

Trait Implementations§

Source§

impl<'a> Debug for Music<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Shows the original regular expression.

Source§

impl<'a> Drop for Music<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> PartialEq for Music<'a>

Source§

fn eq(&self, other: &Music<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> StructuralPartialEq for Music<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Music<'a>

§

impl<'a> RefUnwindSafe for Music<'a>

§

impl<'a> !Send for Music<'a>

§

impl<'a> !Sync for Music<'a>

§

impl<'a> Unpin for Music<'a>

§

impl<'a> UnwindSafe for Music<'a>

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

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.