get_current_song implémenté testé

This commit is contained in:
Justine 2024-08-12 15:43:13 +02:00
parent fdceee8e54
commit 123f41930d
2 changed files with 28 additions and 28 deletions

View File

@ -35,7 +35,7 @@ pub mod audioplayer {
//-----------------------------------------Structs //-----------------------------------------Structs
pub struct AudioPlayer { pub struct AudioPlayer {
///A facility for controlling the playing of sound. ///A facility for controlling the playing of sound.
pub sink: Sink, sink: Sink,
///A handle to the sound device. Must live as long as the sink. ///A handle to the sound device. Must live as long as the sink.
stream: OutputStream, stream: OutputStream,
///List of songs to pick from. ///List of songs to pick from.
@ -93,63 +93,70 @@ pub mod audioplayer {
return Ok(()); return Ok(());
} }
fn get_current_song(&self) { ///Returns a copy of the current song and its index in the playlist
///Or None if the playlist's empty
pub fn get_current_song(&self) -> Option<(SongMeta, usize)> {
if self.playlist.songs.len() == 0 {
return None;
}
let index: usize = self.playlist.songs.len() - self.sink.len();
let songcopy = self.playlist.songs[index].clone();
return Some((songcopy, index));
}
pub fn skip_forward(&mut self) {
unimplemented!(); unimplemented!();
} }
fn skip_forward(&mut self) { pub fn skip_backwards(&mut self) {
unimplemented!(); unimplemented!();
} }
fn skip_backwards(&mut self) { pub fn pause(&mut self) {
unimplemented!(); unimplemented!();
} }
fn pause(&mut self) { pub fn unpause(&mut self) {
unimplemented!(); unimplemented!();
} }
fn unpause(&mut self) { pub fn get_pos(&self) {
unimplemented!(); unimplemented!();
} }
fn get_pos(&self) { pub fn set_vol(&mut self, vol: f32) {
unimplemented!(); unimplemented!();
} }
fn set_vol(&mut self, vol: f32) { pub fn get_vol(&mut self) {
unimplemented!(); unimplemented!();
} }
fn get_vol(&mut self) { pub fn goto(&mut self, index: usize) {
unimplemented!(); unimplemented!();
} }
fn goto(&mut self, index: usize) { pub fn press_shuffle(&mut self) {
unimplemented!(); unimplemented!();
} }
fn press_shuffle(&mut self) { pub fn press_repeat(&mut self) {
unimplemented!(); unimplemented!();
} }
fn press_repeat(&mut self) { pub fn seek(&mut self, goto: Duration) {
unimplemented!(); unimplemented!();
} }
fn seek(&mut self, goto: Duration) { pub fn stop(&mut self) {
unimplemented!(); unimplemented!();
} }
fn stop(&mut self) { pub fn load_file(&mut self) {
unimplemented!(); unimplemented!();
} }
fn load_file(&mut self) { pub fn load_folder(&mut self) {
unimplemented!();
}
fn load_folder(&mut self) {
unimplemented!(); unimplemented!();
} }
} }

View File

@ -23,15 +23,8 @@ fn main() {
let mut player = AudioPlayer::new().unwrap(); let mut player = AudioPlayer::new().unwrap();
player.playlist = playlist; player.playlist = Playlist::new();
dbg!(player.get_current_song());
player.play_at(0).unwrap();
println!("{:?} {:?} {:?}", player.state, player.sink.volume(), player.sink.is_paused());
sleep(Duration::from_secs(10));
player.play_at(2).unwrap();
loop {
dbg!(player.sink.get_pos());
}
} }