Showing the progression of the song
It would be nice to see the cursor moving when the song plays. Let's tackle this challenge right now.
We'll start by adding a method to our Player
to get the duration of a song:
use std::time::Duration; pub fn compute_duration<P: AsRef<Path>>(path: P) -> Option<Duration> { let file = File::open(path).unwrap(); Mp3Decoder::compute_duration(BufReader::new(file)) }
We simply call the compute_duration()
method we created earlier. Next, we'll modify the Playlist
to call this function. But before we do so, we'll modify the State
type from the main
module to include additional information:
use std::collections::HashMap; struct State { current_time: u64, durations: HashMap<String, u64>, stopped: bool, }
We added a current_time
 field, which will contain how much time elapsed since the song started playing. We also store the duration of the songs in a HashMap
so that we only compute it once for each...