示例#1
0
        private bool UpdateSongInfo()
        {
            var status = _spotifyClient.GetStatus();

            var track = status?.Track;

            if (track == null)
            {
                return(false);
            }
            _trackLength = track.Length;

            TrackProgressChanged?.Invoke(this, CalculateTrackPercentange(status.PlayingPosition));
            TrackInfoChanged?.Invoke(this, new TrackInfoChangedEventArgs
            {
                TrackName = track.TrackResource.Name,
                Artist    = track.ArtistResource.Name,
                AlbumArt  = track.GetAlbumArt(AlbumArtSize.Size640)
            });

            if (status.Playing)
            {
                TrackPlaying?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                TrackPaused?.Invoke(this, EventArgs.Empty);
            }

            return(true);
        }
示例#2
0
 private void ResetState()
 {
     TrackInfoChanged?.Invoke(this, new TrackInfoChangedEventArgs {
         TrackName = "", AlbumArt = null
     });
     TrackPaused?.Invoke(this, EventArgs.Empty);
     TrackProgressChanged?.Invoke(this, 0);
 }
示例#3
0
        private void SetBlankState()
        {
            TrackInfoChanged?.Invoke(this, new TrackInfoChangedEventArgs());
            TrackPaused?.Invoke(this, EventArgs.Empty);
            TrackProgressChanged?.Invoke(this, 0);

            _currentIsPlaying = false;
            _currentArtist    = null;
            _currentSong      = null;
        }
示例#4
0
 private void SpotifyClientOnOnPlayStateChange(object sender, PlayStateEventArgs playStateEventArgs)
 {
     if (playStateEventArgs.Playing)
     {
         TrackPlaying?.Invoke(this, EventArgs.Empty);
     }
     else
     {
         TrackPaused?.Invoke(this, EventArgs.Empty);
     }
 }
示例#5
0
        private void CheckSpotifyTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            try
            {
                var spotifyTitle = _spotifyControls.GetSpotifyTitle();

                // Spotify not open
                if (string.IsNullOrEmpty(spotifyTitle))
                {
                    // Already blanked
                    if (!_spotifyRunning)
                    {
                        return;
                    }

                    SetBlankState();

                    _spotifyRunning = false;
                    return;
                }

                _spotifyRunning = true;

                if (spotifyTitle == NotPlayingTitle)
                {
                    // already paused
                    if (!_currentIsPlaying)
                    {
                        return;
                    }

                    TrackPaused?.Invoke(this, EventArgs.Empty);
                    _currentIsPlaying = false;
                    return;
                }

                ExtractTitle(spotifyTitle);
            }
            finally
            {
                _checkSpotifyTimer.Enabled = true;
            }
        }
示例#6
0
        private void NotifyPlayerState()
        {
            var playing = _itunesControls.IsPlaying;

            if (_isPlaying == playing)
            {
                return;
            }

            if (playing)
            {
                TrackPlaying?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                TrackPaused.Invoke(this, EventArgs.Empty);
            }

            _isPlaying = playing;
        }
示例#7
0
        private void NotifyState()
        {
            var isPlaying = _ipc.GetPlayState().HasFlag(MusicBeeIPC.PlayState.Playing);

            if (isPlaying == _isPlaying)
            {
                return;
            }

            if (isPlaying)
            {
                TrackPlaying?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                TrackPaused?.Invoke(this, EventArgs.Empty);
            }

            _isPlaying = isPlaying;
        }