private async void GetSongInfo() { Thread.Sleep(5000); var context = _spotify.GetPlayingTrack(); if (context.Item != null) { try { var album = await _spotify.GetAlbumAsync(context.Item.Album.Id); TrackTimer.Stop(); TrackTimer.Enabled = false; TrackTimer.Interval = (context.Item.DurationMs - context.ProgressMs); TrackTimer.Enabled = true; TrackTimer.Start(); CurrentSongID = context.Item.Id; SongName.Text = context.Item.Name; Artist.Text = context.Item.Artists[0].Name; Album.Text = album.Name + "(" + album.ReleaseDate + ")" /*+ " Songs: " + album.Tracks.Total*/; CopyRight.Text = "Copyright: " + album.Copyrights[0].Text; pictureBox1.Load(album.Images[1].Url); } catch (Exception ex) { MessageBox.Show(ex.Message); } //enable timer if song name is longer then what ever is set //if (SongName.Text.Length > 35 || Artist.Text.Length > 35 || Album.Text.Length > 35 || CopyRight.Text.Length > 35) //{ // timer1.Interval = 1; // timer1.Enabled = false; // timer1.Start(); //} //else //{ // timer1.Stop(); // timer1.Enabled = false; // SongName.Left = 320; // Artist.Left = 320; // Album.Left = 320; // CopyRight.Left = 320; //} } else { SongName.Text = "Failed To Get Song Info"; _spotify = await webApiFactory.GetWebApi(); //Refresh Oauth GetSongInfo(); //Re-get song info } }
protected override void WndProc(ref Message m) { if (m.Msg == Constants.WM_HOTKEY_MSG_ID) { switch (GetKey(m.LParam)) { case Keys.MediaNextTrack: _spotify.SkipPlaybackToNext(); GetSongInfo(); break; case Keys.MediaPreviousTrack: _spotify.SkipPlaybackToPrevious(); GetSongInfo(); break; case Keys.MediaPlayPause: if (SongStopped == 0) { _spotify.PausePlayback(); TrackTimer.Stop(); SongStopped = 1; } else { _spotify.ResumePlayback(); TrackTimer.Start(); SongStopped = 0; } break; case Keys.MediaStop: if (SongStopped == 0) { _spotify.PausePlayback(); TrackTimer.Stop(); SongStopped = 1; } else { _spotify.ResumePlayback(); TrackTimer.Start(); SongStopped = 0; } break; } } base.WndProc(ref m); }
public void OnCurrentTrackChanged(Track track) { CurrentStatus = track == null ? PlayerStatus.Stopped : PlayerStatus.Playing; TrackTimer.Reset(track); _player.Play(track); if (track == null) { return; } TrackTimer.Start(); }
private void OnResume() { _player.Resume(); TrackTimer.Start(); CurrentStatus = PlayerStatus.Playing; }