Пример #1
0
 private void BTN_Stop_Click(object sender, EventArgs e)
 {
     this.player.Stop();
     SongTimer.Stop();
     PRG_SongProgress.Value = 0;
     LBL_SongPercent.Text   = "";
 }
Пример #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                if (EventTimer != null)
                {
                    EventTimer.Stop();
                    EventTimer.Enabled  = false;
                    EventTimer.Elapsed -= ElapsedEventTick;

                    EventTimer.Dispose();
                    EventTimer = null;
                }

                if (SongTimer != null)
                {
                    SongTimer.Stop();
                    SongTimer.Enabled  = false;
                    SongTimer.Elapsed -= ElapsedSongTick;

                    SongTimer.Dispose();
                    SongTimer = null;
                }
            }

            _disposed = true;
        }
Пример #3
0
        public async void ElapsedEventTick(object sender, ElapsedEventArgs e)
        {
            SpotifyLatestStatus = await SpotifyProcess.GetSpotifyStatus();

            if (SpotifyLatestStatus?.CurrentTrack == null)
            {
                EventTimer.Start();
                return;
            }

            var newestTrack = SpotifyLatestStatus.CurrentTrack;

            if (Track != null)
            {
                if (newestTrack.Playing != Track.Playing)
                {
                    if (newestTrack.Playing)
                    {
                        SongTimer.Start();
                    }
                    else
                    {
                        SongTimer.Stop();
                    }

                    await Task.Run(() => OnPlayStateChange?.Invoke(this, new PlayStateEventArgs()
                    {
                        Playing = newestTrack.Playing
                    }));
                }
                if (!newestTrack.Equals(Track))
                {
                    SongTimer.Start();
                    await Task.Run(async() => OnTrackChange?.Invoke(this, new TrackChangeEventArgs()
                    {
                        OldTrack = Track,
                        NewTrack = await SpotifyLatestStatus.GetTrack()
                    }));
                }
                if (Track.CurrentPosition != null || newestTrack != null)
                {
                    await Task.Run(() => OnTrackTimeChange?.Invoke(this, new TrackTimeChangeEventArgs()
                    {
                        TrackTime = newestTrack.Equals(Track) ? Track?.CurrentPosition ?? 0 : 0
                    }));
                }
            }
            if (newestTrack != null)
            {
                newestTrack.CurrentPosition = newestTrack.Equals(Track) ? Track?.CurrentPosition ?? 0 : (int?)null;
                Track = newestTrack;
            }
            EventTimer.Start();
        }
Пример #4
0
 private void BtnStop_Click(object sender, EventArgs e)
 {
     player.Stop();
     SongTimer.Stop();
 }
Пример #5
0
        public async Task TriggerEvents()
        {
            // avoid concurrences
            if (_processingEvents == true)
            {
                return;
            }

            _processingEvents = true;

            SpotifyLatestStatus = await SpotifyProcess.GetSpotifyStatus();

            if (SpotifyLatestStatus?.CurrentTrack != null)
            {
                var newestTrack = SpotifyLatestStatus.CurrentTrack;
                if (Track != null)
                {
                    if (newestTrack.Playing != Track.Playing)
                    {
                        if (newestTrack.Playing)
                        {
                            SongTimer?.Start();
                        }
                        else
                        {
                            SongTimer?.Stop();
                        }

                        _ = Task.Run(() => OnPlayStateChange?.Invoke(this, new PlayStateEventArgs()
                        {
                            Playing = newestTrack.Playing
                        }));
                    }
                    if (!newestTrack.Equals(Track))
                    {
                        SongTimer?.Start();
                        _ = Task.Run(async() => OnTrackChange?.Invoke(this, new TrackChangeEventArgs()
                        {
                            OldTrack = Track,
                            NewTrack = await SpotifyLatestStatus.GetTrack()
                        }));
                    }
                    if (Track.CurrentPosition != null || newestTrack != null)
                    {
                        _ = Task.Run(() => OnTrackTimeChange?.Invoke(this, new TrackTimeChangeEventArgs()
                        {
                            TrackTime = newestTrack.Equals(Track) ? Track?.CurrentPosition ?? 0 : 0
                        }));
                    }
                }

                if (newestTrack != null)
                {
                    newestTrack.CurrentPosition = newestTrack.Equals(Track) ? Track?.CurrentPosition ?? 0 : (int?)null;
                    Track = newestTrack;
                }
            }

            EventTimerStart();

            _processingEvents = false;
        }