public void GetSongs() { XDocument songsXml = XDocument.Load("http://musicbrainz.org/ws/2/release/" + albumMbId + "?inc=recordings"); foreach (XElement x in songsXml.Root.Element(ns + "release").Element(ns + "medium-list").Element(ns + "medium").Element(ns + "track-list").Elements(ns + "track")) { Song temp = new Song(artistName, albumName, x.Element(ns + "recording").Element(ns + "title").Value, x.Element(ns + "length").Value); songsList.Add(temp); } }
public static List<Song> TopTracks(int n, string groupName) { TextWriter writer = new StreamWriter(@"C:\debug.txt", true); Stopwatch sw3 = new Stopwatch(); sw3.Start(); List<Song> TopTrackList = new List<Song>(); try { Stopwatch sw4 = new Stopwatch(); sw4.Start(); try { HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&artist=" + groupName + "&limit=" + n.ToString() + "&api_key=b25b959554ed76058ac220b7b2e0a026"); //XmlReader xmlReader = new XmlReader("http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&artist=" + groupName + "&limit=" + n.ToString() + "&api_key=b25b959554ed76058ac220b7b2e0a026"); HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); Stream receiveStream = myHttpWebResponse.GetResponseStream(); XDocument ttdoc = XDocument.Load(receiveStream); sw4.Stop(); writer.WriteLine("Xml load:" + sw4.ElapsedMilliseconds); foreach (XElement el in ttdoc.Root.Element("toptracks").Elements("track")) { string temp = el.Element("name").Value; string temp2 = el.Element("duration").Value; Song s = new Song(groupName, "", temp, temp2, 0, ""); TopTrackList.Add(s); } } catch (Exception e) { return TopTrackList; } sw3.Stop(); writer.WriteLine("toptrack 1 iter:" + sw3.ElapsedMilliseconds); writer.Close(); return TopTrackList; } catch (TimeoutException e) { writer.WriteLine("LOLOMG"); return TopTrackList; } }
/* public Playlist(int n) { for (int i = 0; i < this.pl.Count; ++i) { this } } */ public void AddSong(Song s) { listOfSongs.Add(s); }
public static void GetSongUri(Song s,string token) { XDocument songUri = XDocument.Load("https://api.vkontakte.ru/method/audio.search.xml?q=" + s.SongName + "-" + s.ArtistName + "&count=1&access_token=" + token); s.Source = songUri.Root.Element("audio").Element("url").Value; }
private void PlaySong(Song s) { //if (s.Source == "") VkSearch.GetSongUri(s, token); Uri ur = new Uri(s.Source); mediaElement1.Source = ur; mediaElement1.LoadedBehavior = MediaState.Manual; mediaElement1.Play(); // timer(); }