Exemple #1
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();
        }
Exemple #2
0
        private void btnPlay_Click(object sender, EventArgs e)
        {
            if (listBoxSongs.SelectedItems.Count < 1)
            {
                return;
            }

            int index = listBoxSongs.Items.IndexOf(listBoxSongs.SelectedItems[0]);

            player.SoundLocation = path[index];

            setSongSlider(path[index]);
            player.Play();
            SetStartParameters();
            SongTimer.Interval = timerInterval;
            SongTimer.Start();
        }
Exemple #3
0
 private void BTN_Play_Click(object sender, EventArgs e)
 {
     this.player.Play();
     SongTimer.Start();
 }
Exemple #4
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;
        }