public static List<Song> parsePlaylist(DAAP.ContentNode node) { if (node == null) return null; List<Song> list = new List<Song>(); DAAP.ContentNode n = node.GetChild("dmap.listing"); foreach (DAAP.ContentNode song in (DAAP.ContentNode[])n.Value) { Song s = new Song(); s.trackAlbum = GetString(song, "daap.songalbum"); s.trackArtist = GetString(song, "daap.songartist"); s.trackID = GetInt(song, "dmap.itemid"); s.trackName = GetString(song, "dmap.itemname"); s.perID = GetLong(song, "dmap.persistentid"); DAAP.ContentNode len = song.GetChild("daap.songtime"); if (len != null) s.trackLength = TimeSpan.FromMilliseconds((int)len.Value); list.Add(s); } return list; }
private static int GetInt(DAAP.ContentNode n, string name) { DAAP.ContentNode t = n.GetChild(name); if (t == null) return 0; else return (int)(t.Value); }
private static ulong GetLong(DAAP.ContentNode n, string name) { DAAP.ContentNode t = n.GetChild(name); if (t == null) return 0; else return (ulong)((long)(t.Value)); }
private static string GetString(DAAP.ContentNode n, string name) { DAAP.ContentNode t = n.GetChild(name); if (t == null) return ""; else return (string)(t.Value); }
private void StatusEvent(DAAP.ContentNode node) { if (mutex.WaitOne(5)) { try { btnPlayThumb.Icon = ((byte)(node.GetChild("tune.status").Value) == 3 ? playIco : pauseIco); if ((byte)(node.GetChild("tune.status").Value) < 3) { mutex.ReleaseMutex(); return; } lblTrack.Text = node.GetChild("tune.track").Value.ToString(); lblArtist.Text = node.GetChild("tune.artist").Value.ToString(); lblAlbum.Text = node.GetChild("tune.album").Value.ToString(); } catch (System.Exception ex) { mutex.ReleaseMutex(); return; } string prev = lblTrack.Text + lblArtist.Text + lblAlbum.Text; if (prev != (string)this.Tag) { this.Tag = prev; Notify.ShowBalloonTip(5000, "Now Playing:", lblTrack.Text + "\n" + lblArtist.Text + "\n" + lblAlbum.Text, ToolTipIcon.Info); string ico = "Now Playing: " + lblTrack.Text; if (ico.Length > 63) Notify.Text = ico.Substring(0, 60) + "..."; else Notify.Text = ico; int songNum; for (songNum = 0; songNum < playlist.Count; ++songNum) { if (playlist[songNum].Name == lblTrack.Text && playlist[songNum].trackArtist == lblArtist.Text) { break; } } currSong = null; nextSong = null; nextNext = null; if (songNum < playlist.Count - 2) { SetMeta(songNum); artBox.Image = (playlist[songNum].art != null ? new Bitmap(playlist[songNum].art, artBox.Size) : null); } if ((songNum > playlist.Count - 5 && playlist.Count > 8) || playlist.Count < 8) { tunes.GetPlaylist(((Playlist)(cmbPlaylist.SelectedItem)).id); } } TimeSpan songPrg = TimeSpan.FromMilliseconds((int)node.GetChild("tune.remaining").Value); TimeSpan songTotal = TimeSpan.Zero; DAAP.ContentNode content = node.GetChild("tune.total"); if (content != null) songTotal = TimeSpan.FromMilliseconds((int)content.Value); if (currSong == null) { int play = 0; if (songTotal.TotalMilliseconds > 0) { play = 100 - (int)((100.0 * songPrg.TotalMilliseconds) / songTotal.TotalMilliseconds); if (prgTimestamp.Value != play) prgTimestamp.Value = play; } songPrg = songTotal - songPrg; lblTimestamp.Text = string.Format("{0}:{1:D2} / {2}:{3:D2}", new object[] { songPrg.Hours * 60 + songPrg.Minutes, songPrg.Seconds, songTotal.Minutes, songTotal.Seconds }); Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance.SetProgressValue(play, 100, this.Handle); } else { currSong.trackLength = songTotal; currSong.trackPos = songPrg; } tunes.GetVolume(); mutex.ReleaseMutex(); } }