We have the ability to create a playlist in our music player, but we cannot save a playlist to a file in order to be able to load one later. Let's add this feature to our project.
We'll save the playlist in the m3u
file format and to handle this format, we'll use the m3u
crate. So let's add it to our Cargo.toml
file:
m3u = "^1.0.0"
Add this line to the main
module:
extern crate m3u;
We'll start by adding a button to save the playlist. First, we add a field in the MusicToolbar
structure for the button:
pub struct MusicToolbar { open_button: ToolButton, next_button: ToolButton, play_button: ToolButton, pub play_image: Image, previous_button: ToolButton, quit_button: ToolButton, remove_button: ToolButton, save_button: ToolButton, stop_button: ToolButton, toolbar: Toolbar, }
And in the constructor, we'll create this button:
impl MusicToolbar { pub fn new() -> Self { let toolbar = Toolbar::new(); ...