The MpdFile class contains all meta data for a file of the MPD.
예제 #1
0
 public void Update(MpdStatus status, MpdFile currentSong)
 {
     playerControl.Update(status, currentSong);
 }
예제 #2
0
    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;
      }
    }
예제 #3
0
    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;
    }
예제 #4
0
    } // UpdateDbFinished

    private void TrackChanged(MpdFile track)
    {
      if (m_Settings.Scrobbler){
        if (m_CurrentTrack != null && m_CurrentTrack.Time >= 30){
          double played = (DateTime.Now - m_CurrentTrackStart).TotalSeconds;
          if (played >= 240 || played >= m_CurrentTrack.Time / 2) 
            m_LastfmScrobbler.Scrobble(m_CurrentTrack.Artist, m_CurrentTrack.Title, m_CurrentTrack.Album, m_CurrentTrackStart);
        }

        if (track != null){
          m_LastfmScrobbler.UpdateNowPlaying(track.Artist, track.Title, track.Album);
        }
      }

      System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetLyrics), track);
      if (track != null && (m_CurrentTrack == null || m_CurrentTrack.Artist != track.Artist))
        System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetArtistInfo), track.Artist);
      else if (track == null)
        System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetArtistInfo), string.Empty);

      if (track != null && (m_CurrentTrack == null || m_CurrentTrack.Artist != track.Artist || m_CurrentTrack.Album != track.Album))
        System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetAlbumInfo), new List<string>() { track.Artist, track.Album});
      else if (track == null)
        System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetAlbumInfo), new List<string>() { string.Empty, string.Empty});


      if (m_NotifyIcon != null && track != null && (m_MiniPlayer == null || !m_MiniPlayer.IsVisible)) {
        string trackText = string.Format("\"{0}\"\r\n{1}", track.Title, track.Artist);
        if (trackText.Length >= 64)
          m_NotifyIcon.Text = string.Format("{0}...", trackText.Substring(0, 60));
        else
          m_NotifyIcon.Text = trackText;

        if (m_NotifyIcon.Visible){
          m_NotifyIcon.BalloonTipText = string.Format("\"{0}\"\r\n{1}\r\n{2}", track.Title, track.Album, track.Artist);
          m_NotifyIcon.BalloonTipTitle = "WpfMpdClient";
          m_NotifyIcon.ShowBalloonTip(2000);
        }
      }
    } // TrackChanged
예제 #5
0
        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);
              }));
        }
예제 #6
0
 void NavigateTo(MpdFile file)
 {
     try
       {
     navigating = true;
     if ((lstArtist.SelectedItems.OfType<ListboxEntry>().Any(m => m.Artist == file.Artist)
       || Select(lstArtist, lstArtist.Items.OfType<ListboxEntry>().FirstOrDefault(m => m.Artist == file.Artist)))
       && Select(lstAlbums, lstAlbums.Items.OfType<ListboxEntry>().FirstOrDefault(m => m.Album == file.Album))
       && Select(lstTracks, lstTracks.Items.OfType<MpdFile>().FirstOrDefault(m => m.File == file.File)))
     {
       tabControl.SelectedIndex = 0;
       tabBrowse.SelectedIndex = 0;
       context.View = true;
     }
       } finally {
     navigating = false;
       }
 }
예제 #7
0
        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;
        }