public override bool Equals(object obj)
        {
            PlayerPlaybackStatus status2 = (PlayerPlaybackStatus)obj;

            return(DeviceName == status2.DeviceName &&
                   DeviceType == status2.DeviceType &&
                   DeviceVolumePercent == status2.DeviceVolumePercent &&
                   Progress == status2.Progress &&
                   IsPlaying == status2.IsPlaying &&
                   Track == status2.Track &&
                   IsAd == status2.IsAd &&
                   Playlist == status2.Playlist);
        }
示例#2
0
        //***********************************************************************************************************************************************************************************************************

        /// <summary>
        /// Get the current playback status
        /// </summary>
        public override void UpdateCurrentPlaybackStatus()
        {
            if (_spotifyWeb == null)
            {
                return;
            }
            PlaybackContext _spotifyPlayback = _spotifyWeb.GetPlayback();

            if (_spotifyPlayback.Error?.Status == 401)    // Error 401: "The access token expired"
            {
                IsConnectionTokenExpired = true;
                if (_wasConnectionTokenExpiredEventRaised == false)
                {
                    _wasConnectionTokenExpiredEventRaised = true;
                    RaiseOnPlayerConnectionTokenExpiredEvent();
                }
                return;
            }

            string playlistID = "", playlistName = "";

            if (_spotifyPlayback.Context != null && _spotifyPlayback.Context.Type == "playlist")
            {
                playlistID   = _spotifyPlayback.Context.Uri.Split(':').Last();
                playlistName = _spotifyWeb?.GetPlaylist(playlistId: playlistID, fields: "name").Name;
            }

            PlayerPlaybackStatus playerPlayback = new PlayerPlaybackStatus()
            {
                DeviceName          = _spotifyPlayback.Device?.Name,
                DeviceType          = _spotifyPlayback.Device?.Type,
                DeviceVolumePercent = (_spotifyPlayback.Device == null ? -1 : _spotifyPlayback.Device.VolumePercent),
                IsPlaying           = _spotifyPlayback.IsPlaying,
                Progress            = new TimeSpan(0, 0, 0, 0, _spotifyPlayback.ProgressMs),
                Track    = convertSpotifyTrackToPlayerTrack(_spotifyPlayback.Item),
                IsAd     = _spotifyPlayback.CurrentlyPlayingType == TrackType.Ad,
                Playlist = playlistID != "" ? new PlayerPlaylist(playlistName, playlistID) : null
            };

            if (playerPlayback.Track != null)
            {
                playerPlayback.Track.Playlist = playerPlayback.Playlist;
            }
            CurrentPlaybackStatus = playerPlayback;
        }
示例#3
0
        //***********************************************************************************************************************************************************************************************************

        /// <summary>
        /// Check if an event has to be raised.
        /// </summary>
        private void ElapsedTick(object sender, ElapsedEventArgs e)
        {
            if (_tmpPlaybackStatus == null)
            {
                UpdateCurrentPlaybackStatus();
                _tmpPlaybackStatus = CurrentPlaybackStatus;
                _eventTimer.Start();
                return;
            }
            UpdateCurrentPlaybackStatus();

            if (CurrentPlaybackStatus == null)
            {
                _eventTimer.Start();
                return;
            }
            if (!CurrentPlaybackStatus.IsPlaying && CurrentPlaybackStatus.Track == null)
            {
                _eventTimer.Start();
                return;
            }
            if (CurrentPlaybackStatus.IsPlaying && _tmpPlaybackStatus.Track != null && CurrentPlaybackStatus.Track == null)
            {
                OnTrackChange?.Invoke(this, new PlayerTrackChangeEventArgs()
                {
                    OldTrack = _tmpPlaybackStatus.Track,
                    NewTrack = null
                });
            }
            if (CurrentPlaybackStatus.Track != null && _tmpPlaybackStatus.Track != null)
            {
                if (CurrentPlaybackStatus.Track?.TrackID != _tmpPlaybackStatus.Track?.TrackID || CurrentPlaybackStatus.Track.Duration != _tmpPlaybackStatus.Track.Duration)
                {
                    OnTrackChange?.Invoke(this, new PlayerTrackChangeEventArgs()
                    {
                        OldTrack = _tmpPlaybackStatus.Track,
                        NewTrack = CurrentPlaybackStatus.Track
                    });
                }
            }
            if (CurrentPlaybackStatus.IsPlaying != _tmpPlaybackStatus.IsPlaying)
            {
                OnPlayStateChange?.Invoke(this, new PlayerPlayStateEventArgs()
                {
                    Playing = CurrentPlaybackStatus.IsPlaying
                });
            }
            if (CurrentPlaybackStatus.DeviceVolumePercent != _tmpPlaybackStatus.DeviceVolumePercent)
            {
                OnVolumeChange?.Invoke(this, new PlayerVolumeChangeEventArgs()
                {
                    OldVolume = _tmpPlaybackStatus.DeviceVolumePercent,
                    NewVolume = CurrentPlaybackStatus.DeviceVolumePercent
                });
            }
            if (CurrentPlaybackStatus.Progress != _tmpPlaybackStatus.Progress)
            {
                OnTrackTimeChange?.Invoke(this, new PlayerTrackTimeChangeEventArgs()
                {
                    TrackTime = CurrentPlaybackStatus.Progress
                });
            }

            _tmpPlaybackStatus = CurrentPlaybackStatus;
            _eventTimer.Start();
            OnPropertyChanged("CurrentPlaybackStatus");
            OnPropertyChanged("CurrentTrack");
        }