January 2018
Beginner to intermediate
454 pages
10h 8m
English
We're now ready to use our music engine. Let's add a couple of new methods to Playlist.
Let's start with a method to get the path of the selection:
fn selected_path(&self) -> Option<String> { let selection = self.treeview.get_selection(); if let Some((_, iter)) = selection.get_selected() { let value = self.model.get_value(&iter, PATH_COLUMN as i32); return value.get::<String>(); } None }
We start by getting the selection, then we get the iterator for the selection. From the iterator, we can get the value at the specified column to get the path. We can now add a method to load the selected song:
pub fn play(&self) -> bool { if let Some(path) = self.selected_path() { self.player.load(&path); true } else { false }