Audioquarium.MainWindow.timer_Tick C# (CSharp) Method

timer_Tick() private method

private timer_Tick ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void timer_Tick(object sender, EventArgs e)
        {
            if (_stopWatch.ElapsedMilliseconds > 100)
            _stopWatch.Reset();

              if (Mplayer.Source != null && Mplayer.NaturalDuration.HasTimeSpan)
              {
            SongGrid.SelectedIndex = SongGrid.SelectedIndex;

            ScrubBar.Minimum = 0;
            ScrubBar.Maximum = Mplayer.NaturalDuration.TimeSpan.TotalSeconds;

            if (!_dragStarted)
            {
              ScrubBar.Value = Mplayer.Position.TotalSeconds;
              if (_selectedSong != null && Mplayer.HasAudio)
              {
            ScrubTime.Content = TimeSpan.FromSeconds(ScrubBar.Value).ToString(@"mm\:ss") + " - " + _selectedSong.Length;
              }
            }
            else
            {
              ScrubTime.Content = TimeSpan.FromSeconds(ScrubBar.Value).ToString(@"mm\:ss") + " - " + _selectedSong.Length;
            }
              }

              // When the song ends
              if (Mplayer.Source != null && Mplayer.NaturalDuration.HasTimeSpan
              && Mplayer.Position.TotalSeconds == Mplayer.NaturalDuration.TimeSpan.TotalSeconds)
              {
            if (_shuffleSongs)
              SongGrid.SelectedIndex = _rnd.Next(0, SongGrid.Items.Count);
            else if (_repeatSong)
              SongGrid.SelectedIndex = SongGrid.SelectedIndex;
            else if (_selectedSong == SongGrid.SelectedItem as Itemsource.Songs)
              Next(); // If the current song is the same as the one playing then go to next

            if (_selectedSong != null)
            {
              Mplayer.Open(new Uri(_selectedSong.FileName));
              Mplayer.Play();
              GetAlbumart();

              _audioPlaying = true;
              if (_selectedSong.Name == null)
            NowPlayingSong.Content = _selectedSong.AltName + " - " + _selectedSong.Artist;
              else
            NowPlayingSong.Content = _selectedSong.Name + " - " + _selectedSong.Artist;

              NowPlayingAlbum.Text = _selectedSong.Album;
              NowPlayingTrack.Text = _selectedSong.Track;
            }
              }
        }