Exemple #1
0
        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;
        }
Exemple #2
0
        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();
              }
        }
Exemple #3
0
        private Bitmap GetItemArt(ref Song song, Size size)
        {
            if (song.art == null)
              {
            // Attempt retrieval
            System.IO.Stream ioStream = tunes.GetItemArt(ref song, artBox.Width, artBox.Height);
            if (ioStream != null && ioStream.Length > 0)
            {
              song.art = new Bitmap(ioStream);
            }
            else
            {
              song.art = Properties.Resources.coverart;
            }
              }

              return (song.art == null ? null : new Bitmap(song.art, size));
        }
Exemple #4
0
        private void SetMeta(int num)
        {
            if (num >= playlist.Count - 2)
            return;

              currSong = playlist[num];

              Song s = nextSong = playlist[num + 1];
              lblTrackNext.Text = s.trackName;
              lblArtistNext.Text = s.trackArtist;
              lblAlbumNext.Text = s.trackAlbum;
              lblLenNext.Text = string.Format("{0}:{1:D2}", s.trackLength.Minutes, s.trackLength.Seconds);
              artNext.Image = GetItemArt(ref s, artNext.Size);

              s = nextNext = playlist[num + 2];
              lblTrackNextNext.Text = s.trackName;
              lblArtistNextNext.Text = s.trackArtist;
              lblAlbumNextNext.Text = s.trackAlbum;
              lblLenNextNext.Text = string.Format("{0}:{1:D2}", s.trackLength.Minutes, s.trackLength.Seconds);
              artNextNext.Image = GetItemArt(ref s, artNext.Size);
        }
Exemple #5
0
        public System.IO.Stream GetItemArt(ref Song song, int w, int h)
        {
            TunesMsg data = new TunesMsg(MsgType.MSG_GET_ART);
              data["song"] = song;
              data["item"] = song.trackID;
              data["w"] = w;
              data["h"] = h;
              lock (msgQueue)
              {
            msgQueue.Enqueue(data);
              }
              /*
              try
              {
            int cnt = 0;
            while (true)
            {
              cnt++;
              System.Net.WebRequest req = System.Net.HttpWebRequest.Create(URL + "databases/" + dbID + "/items/" + item + "/extra_data/artwork?mw=" + w + "&mh=" + h + "&revision-number=" + revId + "&session-id=" + SessID);
              req.Headers.Add("Viewer-Only-Client", "1");
              req.Headers.Add("Accept-Encoding", "gzip, deflate");

              System.Net.WebResponse resp = req.GetResponse();
              System.IO.Stream st;
              if (resp.Headers["Content-encoding"] == "gzip")
            st = new System.IO.Compression.GZipStream(resp.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
              else if (resp.Headers["Content-encoding"] == "deflate")
            st = new System.IO.Compression.DeflateStream(resp.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
              else
            st = resp.GetResponseStream();

              byte[] b = new byte[resp.ContentLength];
              int len = st.Read(b, 0, b.Length);
              Array.Resize<byte>(ref b, len);

              System.IO.MemoryStream stream = new System.IO.MemoryStream();
              stream.Write(b, 0, b.Length);

              if (len > 0 && len < 50)
              {
            if (cnt > 2)
              return null;

            DAAP.ContentNode n = DAAP.ContentParser.Parse(bag, b);

            revId = (int)n.GetChild("dmap.serverrevision").Value;
            continue;
              }

              if (b.Length > 0)
            return stream;
              else
            return null;
            }
              }
              catch (Exception e)
              {*/
            return null;
              //}
        }