public static void ParseRecentPlaylist(string xml) { XDocument doc = XDocument.Parse(xml); foreach (XElement element in doc.Root.Elements()) { XElement x = element.Element("{http://schemas.zune.net/catalog/music/2007/10}track"); if (x != null) { RecentSong song = new RecentSong(); song.Title = x.Element("{http://schemas.zune.net/catalog/music/2007/10}title").Value; song.Album = x.Element("{http://schemas.zune.net/catalog/music/2007/10}album"). Element("{http://schemas.zune.net/catalog/music/2007/10}title").Value; song.Artist = x.Element("{http://schemas.zune.net/catalog/music/2007/10}primaryArtist"). Element("{http://schemas.zune.net/catalog/music/2007/10}name").Value; song.AlbumID = x.Element("{http://schemas.zune.net/catalog/music/2007/10}album") .Element("{http://schemas.zune.net/catalog/music/2007/10}id").Value.Remove(0, 9); WebClient client = new WebClient(); client.DownloadStringAsync(new Uri("http://catalog.zune.net/v3.2/en-US/music/album/" + song.AlbumID)); client.DownloadStringCompleted += (s, e) => HandleDownload(s, e, song); } } }
public SongView(RecentSong song) { this.ALBUM = song.ALBUM; this.ARTIST = song.ARTIST; this.COMMENTS = song.COMMENTS; this.GENRE = song.GENRE; this.ID = song.ID; this.LOCATION = song.LOCATION; this.TITLE = song.TITLE; this.RATING = song.RATING; int start = song.LOCATION.ToLower().IndexOf("music"); this.Location = song.LOCATION.Substring(start + 5); this.Location = this.Location.Replace('\\', '/'); this.Location = baseUrl + "/" + this.Location; }
private static void HandleDownload(object sender, DownloadStringCompletedEventArgs e, RecentSong song) { try { XDocument xdoc = XDocument.Parse(e.Result); string imageId = xdoc.Root.Element("{http://schemas.zune.net/catalog/music/2007/10}image") .Element("{http://schemas.zune.net/catalog/music/2007/10}id").Value.Remove(0, 9); BitmapImage image = new BitmapImage(new Uri(string.Format("http://catalog.zune.net/v3.2/image/{0}?width=100&height=100", imageId))); song.AlbumArt = image; } catch { song.AlbumArt = new BitmapImage(new Uri("Images/unknown.png", UriKind.Relative)); } ProfileViewModelLocator.ProfileModel.RecentPlaylist.Add(song); }