January 2018
Beginner to intermediate
454 pages
10h 8m
English
We can save playlists, but still cannot load them. Let's start by adding a load() method to Playlist:
pub fn load(&self, path: &Path) { let mut reader = m3u::Reader::open(path).unwrap(); for entry in reader.entries() { if let Ok(m3u::Entry::Path(path)) = entry { self.add(&path); } } }
Here, we create a m3u::Reader with the specified path. We loop over the entry and if we were able to retrieve a m3u::Entry::Path, we add it to the playlist widget.
We'll now modify the open dialog to allow selecting M3U files:
fn show_open_dialog(parent: &ApplicationWindow) -> Option<PathBuf> { let mut file = None; let dialog = FileChooserDialog::new(Some("Select an MP3 audio file"), Some(parent), FileChooserAction::Open); let mp3_filter ...