public static void StopTracking() { if (!Tracking) { return; } TrackTimer.Stop(); Tracking = false; }
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 PlayerControlsViewModel(IPlaylist playlist, IPlayer player, TrackTimer trackTimer) { _playlist = playlist; _player = player; MoveNextCommand = new RelayCommand(OnMoveNext, CanMoveNext); MovePreviousCommand = new RelayCommand(OnMovePrevious, CanMovePrevious); PauseCommand = new RelayCommand(OnPause, CanPause); ResumeCommand = new RelayCommand(OnResume, CanResume); SkipToPercentageCommand = new RelayCommand <double>(OnSkip, CanSkip); TrackTimer = trackTimer; TrackTimer.TrackEnded += OnTrackEnded; CurrentStatus = PlayerStatus.Stopped; }
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 OnSkip(double newPercentage) { _player.SkipToPercentage(newPercentage); TrackTimer.SkipToPercentage(newPercentage); }
private void OnResume() { _player.Resume(); TrackTimer.Start(); CurrentStatus = PlayerStatus.Playing; }
private void OnPause() { _player.Pause(); TrackTimer.Stop(); CurrentStatus = PlayerStatus.Paused; }