Struct ModStream

Source
pub struct ModStream { /* private fields */ }

Implementations§

Source§

impl ModStream

Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, Error>

Examples found in repository?
examples/play.rs (line 52)
51fn play_song(path: &Path) {
52    let mut stream = ModStream::from_file(path).unwrap();
53    let duration = HrTime {
54        seconds: stream.get_duration_seconds(),
55    };
56    let filename = path.file_name().unwrap().to_string_lossy();
57    let title = stream.metadata(Metadata::Title).unwrap();
58    let artist = stream.metadata(Metadata::Artist).unwrap();
59    let date = stream.metadata(Metadata::Date).unwrap();
60    let message = stream.metadata(Metadata::Message).unwrap();
61    let tracker = stream.metadata(Metadata::Tracker).unwrap();
62    let made_in_string = match (tracker.as_str().is_empty(), date.as_str().is_empty()) {
63        (true, true) => String::new(),
64        (false, true) => format!("Made in {}\n", tracker),
65        (true, false) => format!("Made in {}\n", date),
66        (false, false) => format!("Made in {} on {}\n", tracker, date),
67    };
68    println!(
69        "Playing {} {}[{}]\n\
70        {}\
71        {}",
72        title,
73        OptStrFmt::new(" by ", artist.as_str(), " "),
74        filename,
75        made_in_string,
76        message
77    );
78    let mut player = SoundStreamPlayer::new(&mut stream);
79    player.play();
80    while player.status() == SoundStatus::PLAYING {
81        let offset = HrTime {
82            seconds: f64::from(player.playing_offset().as_seconds()),
83        };
84        print!("{}/{}\r", offset, duration);
85        let _ = std::io::stdout().flush();
86        std::thread::sleep(std::time::Duration::from_millis(100));
87    }
88    // Leave the output of the previous song on the previous line
89    println!()
90}
Source

pub fn from_memory(data: &[u8]) -> Self

Source

pub fn get_duration_seconds(&self) -> f64

Examples found in repository?
examples/play.rs (line 54)
51fn play_song(path: &Path) {
52    let mut stream = ModStream::from_file(path).unwrap();
53    let duration = HrTime {
54        seconds: stream.get_duration_seconds(),
55    };
56    let filename = path.file_name().unwrap().to_string_lossy();
57    let title = stream.metadata(Metadata::Title).unwrap();
58    let artist = stream.metadata(Metadata::Artist).unwrap();
59    let date = stream.metadata(Metadata::Date).unwrap();
60    let message = stream.metadata(Metadata::Message).unwrap();
61    let tracker = stream.metadata(Metadata::Tracker).unwrap();
62    let made_in_string = match (tracker.as_str().is_empty(), date.as_str().is_empty()) {
63        (true, true) => String::new(),
64        (false, true) => format!("Made in {}\n", tracker),
65        (true, false) => format!("Made in {}\n", date),
66        (false, false) => format!("Made in {} on {}\n", tracker, date),
67    };
68    println!(
69        "Playing {} {}[{}]\n\
70        {}\
71        {}",
72        title,
73        OptStrFmt::new(" by ", artist.as_str(), " "),
74        filename,
75        made_in_string,
76        message
77    );
78    let mut player = SoundStreamPlayer::new(&mut stream);
79    player.play();
80    while player.status() == SoundStatus::PLAYING {
81        let offset = HrTime {
82            seconds: f64::from(player.playing_offset().as_seconds()),
83        };
84        print!("{}/{}\r", offset, duration);
85        let _ = std::io::stdout().flush();
86        std::thread::sleep(std::time::Duration::from_millis(100));
87    }
88    // Leave the output of the previous song on the previous line
89    println!()
90}
Source

pub fn metadata<'a, K: Key<'a>>(&self, key: K) -> Option<OpenMptString>

Examples found in repository?
examples/play.rs (line 57)
51fn play_song(path: &Path) {
52    let mut stream = ModStream::from_file(path).unwrap();
53    let duration = HrTime {
54        seconds: stream.get_duration_seconds(),
55    };
56    let filename = path.file_name().unwrap().to_string_lossy();
57    let title = stream.metadata(Metadata::Title).unwrap();
58    let artist = stream.metadata(Metadata::Artist).unwrap();
59    let date = stream.metadata(Metadata::Date).unwrap();
60    let message = stream.metadata(Metadata::Message).unwrap();
61    let tracker = stream.metadata(Metadata::Tracker).unwrap();
62    let made_in_string = match (tracker.as_str().is_empty(), date.as_str().is_empty()) {
63        (true, true) => String::new(),
64        (false, true) => format!("Made in {}\n", tracker),
65        (true, false) => format!("Made in {}\n", date),
66        (false, false) => format!("Made in {} on {}\n", tracker, date),
67    };
68    println!(
69        "Playing {} {}[{}]\n\
70        {}\
71        {}",
72        title,
73        OptStrFmt::new(" by ", artist.as_str(), " "),
74        filename,
75        made_in_string,
76        message
77    );
78    let mut player = SoundStreamPlayer::new(&mut stream);
79    player.play();
80    while player.status() == SoundStatus::PLAYING {
81        let offset = HrTime {
82            seconds: f64::from(player.playing_offset().as_seconds()),
83        };
84        print!("{}/{}\r", offset, duration);
85        let _ = std::io::stdout().flush();
86        std::thread::sleep(std::time::Duration::from_millis(100));
87    }
88    // Leave the output of the previous song on the previous line
89    println!()
90}

Trait Implementations§

Source§

impl Drop for ModStream

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl SoundStream for ModStream

Source§

fn get_data(&mut self) -> (&mut [i16], bool)

Request a new chunk of audio samples from the stream source. Read more
Source§

fn seek(&mut self, offset: Time)

Change the current playing position in the stream source.
Source§

fn sample_rate(&self) -> u32

Get the stream sample rate of the stream.
Source§

fn channel_count(&self) -> u32

Return the number of channels of the stream.

Auto Trait Implementations§

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.