public void forward(ref Status status) { using (WebClient wc = new WebClient()) { try { wc.DownloadData("http://localhost:" + portNumber + "/next"); Form1.updateTime = 3000; Form1.refreshTime = 0; } catch { } } }
public void downloadArt(Status status) { using (WebClient wc = new WebClient()) { try { if (!File.Exists("album/" + status.ArtistName + " - " + status.AlbumName + ".jpg")) { wc.DownloadFile(status.ArtURL, "album/" +status.ArtistName + " - " + status.AlbumName + ".jpg"); } } catch { } } }
private void poll() { Stopwatch stop = new Stopwatch(); long change = 0; while (true) { try { oldPos = current.Position; if (imageInvalid) { try { album = Image.FromFile("album/" + current.ArtistName + " - " + current.AlbumName + ".jpg"); } catch { album = Image.FromFile("default.jpg"); } } if (current.Position < (oldPos - 2000)) current = api.getCurrentStatus(); if (current.Playing) { current.Position += change; current.Life += change; if (current.Life > (current.Duration / 10)) { current.Life = long.MinValue; api.submitPlay(current); } if (current.Position >= current.Duration) { nowPlaying = "Finished " + current.SongName + " by " + current.ArtistName + " on " + current.AlbumName; imageInvalid = true; current.Playing = false; current = api.getCurrentStatus(); Thread.Sleep(200); continue; } nowPlaying = "Now playing " + current.SongName + " by " + current.ArtistName + " on " + current.AlbumName; } else { nowPlaying = "Paused " + current.SongName + " by " + current.ArtistName + " on " + current.AlbumName; } canvas.Invalidate(); if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.TopMost = true; }); } stop.Start(); Thread.Sleep(100); stop.Stop(); change = stop.ElapsedMilliseconds; stop.Reset(); refreshTime += change; if (refreshTime > updateTime) { refreshTime = 0; long life = current.Life; string title = current.SongName; current = api.getCurrentStatus(); if (title.Equals(current.SongName)) current.Life = life; if (updateTime == 3000) imageInvalid = true; updateTime = 30000; } scrollLoc -= 5.0f; scrollLoc2 -= 5.0f; } catch { } } }
private void Form1_Load(object sender, EventArgs e) { screen = Screen.FromControl(this).Bounds.Size; this.FormBorderStyle = FormBorderStyle.None; iws = GetWindowLong(this.Handle, -20); int n = iws | 0x20 | 0x80000; SetWindowLong(this.Handle, -20, n); this.TopMost = true; this.Opacity = 0.8; this.Location = new Point(screen.Width - 200, screen.Height - 114); this.Size = new Size(200, 75); this.WindowState = FormWindowState.Minimized; this.Hide(); current = api.getCurrentStatus(); Thread t = new Thread(new ThreadStart(poll)); t.Start(); if (!Directory.Exists("album")) { Directory.CreateDirectory("album"); } }
public Status getCurrentStatus() { Status s = new Status(); using (WebClient wc = new WebClient()) { try { String res = wc.DownloadString("http://localhost:" + portNumber + "/currentSong"); foreach (string l in res.Split(new string[] { "\n" }, StringSplitOptions.None)) { string[] kv = l.Split(' '); switch (kv[0]) { case "status:": s.State = kv[1]; break; case "songName:": s.SongName = l.Substring(10); break; case "artistName:": s.ArtistName = l.Substring(12); break; case "albumName:": s.AlbumName = l.Substring(11); break; case "trackNum:": s.TrackNo = int.Parse(kv[1]); break; case "artURL:": s.ArtURL = kv[1]; break; case "calculatedDuration:": s.Duration = double.Parse(kv[1]); break; case "position:": s.Position = double.Parse(kv[1]); break; default: break; } } downloadArt(s); return s; } catch (Exception ex) { Console.WriteLine(ex.Message); } } return null; }
public bool togglePlay(ref Status status) { using (WebClient wc = new WebClient()) { try { wc.DownloadData("http://localhost:" + portNumber + "/play"); long life = status.Life; string title = status.SongName; Status now = getCurrentStatus(); if (title.Equals(now.SongName)) now.Life = life; status = now; if (now.Playing) { status.Playing = true; } else { status.Playing = false; } status.Position = now.Position; } catch { } } return false; }
public void submitPlay(Status status) { using (WebClient wc = new WebClient()) { try { //need to create dynamic } catch { } } }