pub struct ModStream { /* private fields */ }
Implementations§
Source§impl ModStream
impl ModStream
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, Error>
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}
pub fn from_memory(data: &[u8]) -> Self
Sourcepub fn get_duration_seconds(&self) -> f64
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}
Sourcepub fn metadata<'a, K: Key<'a>>(&self, key: K) -> Option<OpenMptString>
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 SoundStream for ModStream
impl SoundStream for ModStream
Auto Trait Implementations§
impl Freeze for ModStream
impl RefUnwindSafe for ModStream
impl !Send for ModStream
impl !Sync for ModStream
impl Unpin for ModStream
impl UnwindSafe for ModStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more