/// <summary> /// Saves the playlist xml to a file /// </summary> /// <param name="filePath"></param> public void SavePlaylist(string filePath) { if (HasFiles) { XmlDocument xmlDoc = new XmlDocument(); // add zpil processing instruction xmlDoc.AppendChild(xmlDoc.CreateProcessingInstruction("zpl", "version=\"2.0\"")); // create root XmlNode smil = AddNode(xmlDoc, XmlNodeType.Element, xmlDoc, "smil", null); #region <head> // create head XmlNode head = AddNode(xmlDoc, XmlNodeType.Element, smil, "head", null); // add guid and title to head AddNode(xmlDoc, XmlNodeType.Element, head, "guid", string.Format("{{0}}", Guid.ToString())); AddNode(xmlDoc, XmlNodeType.Element, head, "title", Title); // add meta tags AddMetaTag(xmlDoc, head, "generator", "MediaVF Zune Playlist Creator"); AddMetaTag(xmlDoc, head, "itemCount", AudioFiles.Count.ToString()); AddMetaTag(xmlDoc, head, "totalDuration", TotalDuration.TotalMilliseconds.ToString()); #endregion #region <body> // create body XmlNode body = AddNode(xmlDoc, XmlNodeType.Element, smil, "body", null); XmlNode seq = AddNode(xmlDoc, XmlNodeType.Element, body, "seq", null); // add audio files AudioFiles.ForEach(audioFile => { // create media node XmlNode media = AddNode(xmlDoc, XmlNodeType.Element, seq, "media", null); // add attributes AddNode(xmlDoc, XmlNodeType.Attribute, media, "src", audioFile.Path); AddNode(xmlDoc, XmlNodeType.Attribute, media, "albumTitle", audioFile.Album); AddNode(xmlDoc, XmlNodeType.Attribute, media, "albumArtist", audioFile.Artist); AddNode(xmlDoc, XmlNodeType.Attribute, media, "trackTitle", audioFile.Title); AddNode(xmlDoc, XmlNodeType.Attribute, media, "trackArtist", audioFile.Artist); AddNode(xmlDoc, XmlNodeType.Attribute, media, "duration", audioFile.Duration.HasValue ? audioFile.Duration.Value.TotalMilliseconds.ToString() : "0"); }); #endregion // save doc to path xmlDoc.Save(Path.Combine(filePath, Title, ".zpl")); } }
public AudioFileCollection Copy() { AudioFileCollection newFileCollection = new AudioFileCollection(); AudioFiles.ForEach(audioFile => { newFileCollection.Add(audioFile.Copy()); }); return(newFileCollection); }