Once the playlists are displayed in the listbox, the user can select the playlists to be exported and then click the “Convert” button. Here’s the code that is triggered by the button click:
private void btnConvert_Click(object sender, EventArgs e) { // check existence of psPath DirectoryInfo di = new DirectoryInfo(txtResultPath.Text+"\\"); if (!di.Exists) { MessageBox.Show ("Path to write to does not exist", "Problem", MessageBoxButtons.OK,MessageBoxIcon.Error); return; } foreach (Playlist pl in lbPlaylists.SelectedItems) { WriteToFile(pl, Path.GetDirectoryName(txtResultPath.Text+"\\")); } MessageBox.Show("Playlists written","Info",MessageBoxButtons.OK,MessageBoxIcon.Information); }
Here’s this method:
private void WriteToFile(Playlist pl, String psPath) { //create the file - overwrite if necessary FileInfo fi = new FileInfo (Path.Combine (psPath, pl.name() + ".m3u")); StreamWriter fs = new StreamWriter(fi.Open(FileMode.Create)); // write stuff foreach (String trackID in pl.getTrackIDs()) { String trackLocation = _library.GetTrackLocation(trackID); // now remove the "local" part of the location int pos = trackLocation.IndexOf("/iTunes Music/"); string newFileName = trackLocation.Substring(pos+13); newFileName = "//Marvin/musik" + newFileName; newFileName = newFileName.Replace("/", "\\"); fs.WriteLine(newFileName); } fs.Close(); }
No comments:
Post a Comment