public void Update(MpdStatus status, MpdFile currentSong) { if (status == null) return; m_Status = status; btnShuffle.IsChecked = status.Random; btnRepeat.IsChecked = status.Repeat; btnStop.IsEnabled = status.State != MpdState.Stop; switch (status.State) { case MpdState.Play: btnPlay.Visibility = Visibility.Collapsed; btnPause.Visibility = Visibility.Visible; m_Timer.Start(); break; case MpdState.Pause: case MpdState.Stop: btnPlay.Visibility = Visibility.Visible; btnPause.Visibility = Visibility.Collapsed; m_Timer.Stop(); break; } if (status.TimeTotal > 0) { sliTime.Maximum = status.TimeTotal; if (!m_TimeDragging){ sliTime.Value = status.TimeElapsed; lblTimeBefore.Content = Utilities.FormatSeconds(status.TimeElapsed); lblTimeAfter.Content = Utilities.FormatSeconds(status.TimeTotal - status.TimeElapsed); } } else { sliTime.Value = 0; lblTimeBefore.Content = Utilities.FormatSeconds(0); lblTimeAfter.Content = Utilities.FormatSeconds(0); } if (!m_VolumeDragging) { lblVolume.Content = string.Format("{0}", status.Volume); m_IgnoreVolumeChange = true; sliVolume.Value = status.Volume; m_IgnoreVolumeChange = false; } if (currentSong != null) { lblTitle.Text = currentSong.Title; if (!string.IsNullOrEmpty(currentSong.Date)) lblAlbum.Text = string.Format("{0} ({1})", currentSong.Album, currentSong.Date); else lblAlbum.Text = currentSong.Album; lblArtist.Text = currentSong.Artist; if (currentSong.Album != m_Album || currentSong.Artist != m_Artist){ m_Album = currentSong.Album; m_Artist = currentSong.Artist; imgArt.Source = null; ThreadPool.QueueUserWorkItem(new WaitCallback(GetAlbumArt)); } m_Title = currentSong.Title; }else{ lblTitle.Text = Mpc.NoTitle; lblAlbum.Text = Mpc.NoAlbum; lblArtist.Text = Mpc.NoArtist; imgArt.Source = null; } }
public void Update(MpdStatus status, MpdFile currentSong) { playerControl.Update(status, currentSong); }
private void TimerHandler(object sender, ElapsedEventArgs e) { if (!m_Mpc.Connected) return; MpdStatus status = m_Mpc.Status(); // Update db finished: if (m_LastStatus != null && m_LastStatus.UpdatingDb > 0 && status.UpdatingDb <= 0){ Dispatcher.BeginInvoke(new Action(() => { UpdateDbFinished(); })); } // Playlist changed if (m_LastStatus != null && m_LastStatus.Playlist != status.Playlist) { Dispatcher.BeginInvoke(new Action(() => { PopulatePlaylist(); })); } m_LastStatus = status; Dispatcher.BeginInvoke(new Action(() => { MenuItem m = m_NotifyIconMenu.Items[1] as MenuItem; m.Visibility = status.State != MpdState.Play ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; m = m_NotifyIconMenu.Items[2] as MenuItem; m.Visibility = status.State == MpdState.Play ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; MpdFile file = m_Mpc.CurrentSong(); if (m_CurrentTrack == null || file == null || m_CurrentTrack.Id != file.Id) { TrackChanged(file); m_CurrentTrack = file; m_CurrentTrackStart = DateTime.Now; } SelectCurrentTrack(); btnUpdate.IsEnabled = status.UpdatingDb <= 0; playerControl.Update(status); })); }
private async void MpcIdleSubsystemsChanged(Mpc connection, Mpc.Subsystems subsystems) { if (!CheckMpdConnection()) return; MpdStatus status = null; try{ status = await Task.Factory.StartNew(() => m_Mpc.Status()); }catch{ return; } if ((subsystems & Mpc.Subsystems.player) != 0 || (subsystems & Mpc.Subsystems.mixer) != 0 || (subsystems & Mpc.Subsystems.options) != 0){ await Dispatcher.BeginInvoke(new Action( async () => { MenuItem m = m_NotifyIconMenu.Items[1] as MenuItem; m.Visibility = status.State != MpdState.Play ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; m = m_NotifyIconMenu.Items[2] as MenuItem; m.Visibility = status.State == MpdState.Play ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; MpdFile file = await Task.Factory.StartNew(() => m_Mpc.CurrentSong()); playerControl.Update(status, file); if (m_MiniPlayer != null) m_MiniPlayer.Update(status, file); if (m_CurrentTrack == null || file == null || m_CurrentTrack.Id != file.Id) { TrackChanged(file); m_CurrentTrack = file; CurrentTrackId = file != null ? file.Id : 0; m_CurrentTrackStart = DateTime.Now; } })); } if ((subsystems & Mpc.Subsystems.playlist) != 0){ await PopulatePlaylist(); } if ((subsystems & Mpc.Subsystems.update) != 0){ int lastUpdate = m_LastStatus != null ? m_LastStatus.UpdatingDb : -1; await Dispatcher.BeginInvoke(new Action(() => { btnUpdate.IsEnabled = status.UpdatingDb <= 0; // Update db finished: if (lastUpdate > 0 && status.UpdatingDb <= 0) UpdateDbFinished(); })); } //if ((subsystems & Mpc.Subsystems.subscription) != 0) // PopulateChannels(); //if ((subsystems & Mpc.Subsystems.message) != 0) // PopulateMessages(); m_LastStatus = status; }
private void MpcIdleSubsystemsChanged(Mpc connection, Mpc.Subsystems subsystems) { if (m_Mpc == null || !m_Mpc.Connected) return; MpdStatus status = null; try{ status = m_Mpc.Status(); }catch{ return; } if ((subsystems & Mpc.Subsystems.output) != 0) { var os = m_Mpc.Outputs(); Outputs.Where(o => !os.Any(_ => _.Name == o.Name && ((o.IsEnabled = _.IsEnabled) || true))).ToList().Count(Outputs.Remove); os.Where(o => o.Name != "Quiet" && !Outputs.Any(_ => _.Name == o.Name)).Select(o => new Output() { Name = o.Name, Id = o.Id, IsEnabled = o.IsEnabled, Mpc = m_Mpc, }).Do(Outputs.Add); } if ((subsystems & Mpc.Subsystems.player) != 0 || (subsystems & Mpc.Subsystems.mixer) != 0 || (subsystems & Mpc.Subsystems.options) != 0){ Dispatcher.BeginInvoke(new Action(() => { MenuItem m = m_NotifyIconMenu.Items[1] as MenuItem; m.Visibility = status.State != MpdState.Play ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; m = m_NotifyIconMenu.Items[2] as MenuItem; m.Visibility = status.State == MpdState.Play ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; MpdFile file = m_Mpc.CurrentSong(); if (file != null) { ListboxEntry album; if (Albums.TryGetValue(file.Artist + ":" + file.Album, out album)) file.AlbumEntry = album; else { file.AlbumEntry = album = new ListboxEntry(); album.Info = new ObservableCollection<object>(); Action<IList<object>, string, int, System.Windows.Threading.Dispatcher> find = FindInfo; find.BeginInvoke( album.Info, dir.Replace(file.File, "$1"), 5, Dispatcher, find.EndInvoke, null ); } } playerControl.Update(status, file); if (m_MiniPlayer != null) m_MiniPlayer.Update(status, file); if (m_CurrentTrack == null || file == null || m_CurrentTrack.Id != file.Id) { TrackChanged(file); m_CurrentTrack = file; CurrentTrackId = file != null ? file.Id : 0; m_CurrentTrackStart = DateTime.Now; } })); } if ((subsystems & Mpc.Subsystems.playlist) != 0){ Dispatcher.BeginInvoke(new Action(() => { PopulatePlaylist(); })); } if ((subsystems & Mpc.Subsystems.update) != 0){ int lastUpdate = m_LastStatus != null ? m_LastStatus.UpdatingDb : -1; Dispatcher.BeginInvoke(new Action(() => { btnUpdate.IsEnabled = status.UpdatingDb <= 0; // Update db finished: if (lastUpdate > 0 && status.UpdatingDb <= 0) UpdateDbFinished(); })); } if ((subsystems & Mpc.Subsystems.subscription) != 0) PopulateChannels(); if ((subsystems & Mpc.Subsystems.message) != 0) PopulateMessages(); m_LastStatus = status; }