Exemple #1
0
 internal void TunesHandleEvent(TunesMsg data)
 {
     try
       {
     Invoke(new delegateHandleTunes(tunesHandleEventDlg), new object[] { data });
       }
       catch (ObjectDisposedException ex)
       {
     // Form died during invoke (exiting, most likely)
       }
 }
Exemple #2
0
        private void tunesHandleEventDlg(TunesMsg msg)
        {
            //System.Diagnostics.Debug.WriteLine("Main-thread - tunes event: " + System.Enum.GetName(msg.ReqType.GetType(), msg.ReqType));
              switch (msg.ReqType)
              {
            case MsgType.MSG_GETVOL:
              Vol.Value = (int)msg["vol"];
              break;

            case MsgType.MSG_STATUS:
              StatusEvent((DAAP.ContentNode)msg["status"]);
              break;

            case MsgType.MSG_GET_PLAYLIST:
              if ((int)(msg.data["plId"]) == ((Playlist)(cmbPlaylist.SelectedItem)).id)
              {
            NowPlayingPlaylist((List<Song>)msg.data["plist"]);
              }

              if ((int)(msg.data["plId"]) == tunes.MusicID)
              {
            //AllMusicSource.DataSource = (List<Song>)msg.data["plist"];
            musicDB = (List<Song>)msg.data["plist"];
            DataTable t = new DataTable();
            DataColumn c = new DataColumn("id", System.Type.GetType("System.Int32"));
            c.Unique = true;
            t.Columns.Add(c);
            c = new DataColumn("name", System.Type.GetType("System.String"));
            t.Columns.Add(c);
            c = new DataColumn("album", System.Type.GetType("System.String"));
            t.Columns.Add(c);
            c = new DataColumn("artist", System.Type.GetType("System.String"));
            t.Columns.Add(c);
            DataColumn[] pk = new DataColumn[1];
            pk[0] = t.Columns["id"];
            t.PrimaryKey = pk;

            for (int i = 0; i < musicDB.Count; ++i)
            {
              Song s = musicDB[i];
              DataRow r = t.NewRow();
              r["id"] = i;
              r["name"] = s.Name;
              r["album"] = s.Album;
              r["artist"] = s.Artist;
              t.Rows.Add(r);
            }
            AllMusicSource.DataSource = t;
              }
              break;

            case MsgType.MSG_GET_ART:
              // Go thru current and the two meta thingies to see if the id's match... if so, we have art!
              int id = (int)msg.data["item"];
              System.IO.Stream stream = (System.IO.Stream)msg.data["art"];
              if (stream != null)
              {
            try
            {
              if (id == currSong.trackID)
              {
                currSong.art = new Bitmap(stream);
                artBox.Image = currSong.art;
              }
              else if (id == nextSong.trackID)
              {
                nextSong.art = new Bitmap(stream);
                artNext.Image = new Bitmap(nextSong.art, artNext.Size);
              }
              else if (id == nextNext.trackID)
              {
                nextNext.art = new Bitmap(stream);
                artNextNext.Image = new Bitmap(nextNext.art, artNextNext.Size);
              }
            }
            catch (Exception e)
            {
            }
              }
              break;

            case MsgType.MSG_NO_SERVER:
              // Lost connection ?
              System.Diagnostics.Debug.WriteLine("Main thread - system.net.exception: " + msg.data["msg"].ToString());
              break;

            default:
              System.Diagnostics.Debug.WriteLine("Main thread - unknown event: " + System.Enum.GetName(msg.ReqType.GetType(), msg.ReqType));
              break;
              }
        }
Exemple #3
0
 private void threadSetVolume(TunesMsg data)
 {
     GetDAAP("ctrl-int/1/setproperty?dmcp.volume=" + data["vol"] + ".000000");
 }
Exemple #4
0
 private void threadVoteSong(TunesMsg data)
 {
     GetDAAP("ctrl-int/1/setproperty?com.apple.itunes.jukebox-vote=1&item-spec='dmap.itemid:" + data["id"] + "'"); //cue?command=add&query='dmap.itemid:" + id + "'");
 }
Exemple #5
0
        private System.IO.Stream threadGetArt(TunesMsg data)
        {
            try
              {
            int cnt = 0;
            while (true)
            {
              cnt++;
              System.Net.WebRequest req = System.Net.HttpWebRequest.Create(URL + "databases/" + dbID + "/items/" + data["item"] + "/extra_data/artwork?mw=" + data["w"] + "&mh=" + data["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;
              }
        }
Exemple #6
0
 private List<Song> threadGetPlaylist(TunesMsg data)
 {
     return Song.parsePlaylist(GetDAAP("databases/" + dbID + "/containers/" + data["plId"] + "/items?revision-id=" + revId + "&type=music&meta=dmap.itemid,dmap.persistentid,dmap.itemname,daap.songalbum,daap.songartist,daap.songtime"));
 }
Exemple #7
0
        public void VoteSong(ulong pid, int id)
        {
            //&database-spec='dmap.persistentid=" + pid + "'&
              TunesMsg data = new TunesMsg(MsgType.MSG_VOTE);
              data["pid"] = pid;
              data["id"] = id;
              msgQueue.Enqueue(data);

              //DAAP.ContentNode n = GetDAAP("ctrl-int/1/setproperty?com.apple.itunes.jukebox-vote=1&item-spec='dmap.itemid:" + id + "'"); //cue?command=add&query='dmap.itemid:" + id + "'");
        }
Exemple #8
0
        private void commsThread()
        {
            try
              {
            while (true)
            {
              while (msgQueue.Count == 0)
            System.Threading.Thread.Sleep(250);

              // :)
              TunesMsg msg;
              lock (msgQueue)
              {
            msg = msgQueue.Dequeue();
              }

              System.Diagnostics.Debug.WriteLine("comms request: " + System.Enum.GetName(msg.ReqType.GetType(), msg.ReqType));

              switch (msg.ReqType)
              {
            case MsgType.MSG_GET_PLAYLIST:
              msg["plist"] = threadGetPlaylist(msg);
              break;

            case MsgType.MSG_GETVOL:
              msg["vol"] = threadGetVolume();
              break;

            case MsgType.MSG_SETVOL:
              threadSetVolume(msg);
              break;

            case MsgType.MSG_SKIP_NEXT:
              threadSkipNext();
              break;

            case MsgType.MSG_SKIP_PREV:
              threadSkipPrev();
              break;

            case MsgType.MSG_STATUS:
              msg["status"] = threadStatus();
              break;

            case MsgType.MSG_VOTE:
              threadVoteSong(msg);
              break;

            case MsgType.MSG_PLAYPAUSE:
              threadPlayPause();
              break;

            case MsgType.MSG_GET_ART:
              msg["art"] = threadGetArt(msg);
              break;

            default:
              System.Diagnostics.Debug.WriteLine("Unknown request type: " + System.Enum.GetName(msg.ReqType.GetType(), msg.ReqType));
              break;
              }
              parent.TunesHandleEvent(msg);
            }
              }
              catch (System.Threading.ThreadAbortException ex)
              {
            // Thread ending
              }
              catch (System.Net.WebException ex)
              {
            // Server ran away
            TunesMsg evt = new TunesMsg(MsgType.MSG_NO_SERVER);
            evt.data["msg"] = ex.Message;
            parent.TunesHandleEvent(evt);
              }
        }
Exemple #9
0
        public void Status()
        {
            TunesMsg data = new TunesMsg(MsgType.MSG_STATUS);
              lock (msgQueue)
              {
            msgQueue.Enqueue(data);
              }

              //DAAP.ContentNode node = GetDAAP("ctrl-int/1/playstatusupdate?revision-number=" + revId);
              //return null;
        }
Exemple #10
0
 public bool SetVolume(int volPercent)
 {
     TunesMsg data = new TunesMsg(MsgType.MSG_SETVOL);
       data["vol"] = volPercent;
       lock (msgQueue)
       {
     msgQueue.Enqueue(data);
       }
       //
       return true;
 }
Exemple #11
0
        public void GetPlaylist(int plId)
        {
            TunesMsg data = new TunesMsg(MsgType.MSG_GET_PLAYLIST);
              data["plId"] = plId;
              msgQueue.Enqueue(data);

              //return Song.parsePlaylist(GetDAAP("databases/" + dbID + "/containers/" + plId + "/items?revision-id=1&type=music&meta=dmap.itemid,dmap.persistentid,dmap.itemname,daap.songalbum,daap.songartist,daap.songtime"));
        }
Exemple #12
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;
              //}
        }
Exemple #13
0
        public System.IO.Stream GetArt(int w, int h)
        {
            TunesMsg data = new TunesMsg(MsgType.MSG_GET_ART);
              data["w"] = w;
              data["h"] = h;
              lock (msgQueue)
              {
            msgQueue.Enqueue(data);
              }
              /*
              try
              {
            System.Net.WebRequest req = System.Net.HttpWebRequest.Create(URL + "ctrl-int/1/nowplayingartwork?mw=" + w + "&mh=" + h + "&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 (b.Length > 0)
              return stream;
            else
              return null;
              }
              catch (Exception e)
              {*/
            return null;
              //}
        }