public NewSessionIdEvent(
     [NotNull] String sessionId,
     [NotNull] SpotifyState state)
 {
     this.sessionId = sessionId;
     this.state     = state;
 }
Esempio n. 2
0
 public override void Dispose()
 {
     if (_currentState == SpotifyState.Playing)
     {
         StopMusic();
     }
     if (_currentState == SpotifyState.LoggedIn)
     {
         LogOut();
     }
     if (_currentState == SpotifyState.Initialized)
     {
         try
         {
             Spotify.MusicDataAvailable -= OnMusicDataAvailable;
             Spotify.CheckBuffer        -= OnCheckBuffer;
             Spotify.Dispose();
             Spotify = null;
         }
         catch (Exception e)
         {
             // TODO: We should probably figure out what is causing that exception,
             //       in case it is something we can fix.
             Console.WriteLine(e.ToString());
         }
         _currentState = SpotifyState.Disposed;
     }
     base.Dispose();
 }
Esempio n. 3
0
 public void LogIn()
 {
     if (_currentState == SpotifyState.Initialized)
     {
         Spotify.LogIn();
         _currentState = SpotifyState.LoggedIn;
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Skipping to next track.
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public static TransitionInfo SkippedNext([NotNull] SpotifyState state)
        {
            var trans = new TransitionInfo(Reason.fwdbtn, Reason.fwdbtn);

            if (state.GetCurrentPlayable() != null)
            {
                trans.EndedWhen = state.GetPosition();
            }
            return(trans);
        }
Esempio n. 5
0
 public void StopMusic()
 {
     if (_currentState == SpotifyState.Playing)
     {
         _currentState = SpotifyState.LoggedIn;
         Spotify.StopMusic();
         StopStream(_streamKey);
         LogOut();
         _provider = null;
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Updates the current state of the spotify process.
        /// </summary>
        /// <param name="newState">The new state of the spotify process.</param>
        /// <param name="newSong">The currently playing song, if applicable.</param>
        protected void UpdateState(SpotifyState newState, SongInfo? newSong = null) {
            var prevSong = ActiveSong;
            var prevState = State;
            ActiveSong = newSong;
            State = newState;

            if (prevState != newState)
                OnSpotifyStateChanged(prevState, newState);
            if (prevSong != newSong)
                OnActiveSongChanged(prevSong, newSong);
        }
Esempio n. 7
0
 public void LogOut()
 {
     if (_currentState == SpotifyState.Playing)
     {
         StopMusic();
     }
     if (_currentState == SpotifyState.LoggedIn)
     {
         Spotify.LogOut();
         _currentState = SpotifyState.Initialized;
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Skipping to another track in the same context.
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public static TransitionInfo SkipTo([NotNull] SpotifyState state)
        {
            var trans = new TransitionInfo(
                Reason.endplay,
                Reason.clickrow);

            if (state.GetCurrentPlayable() != null)
            {
                trans.EndedWhen = state.GetPosition();
            }
            return(trans);
        }
Esempio n. 9
0
 public override void Initialize(IConfigurationManager manager)
 {
     base.Initialize(manager);
     if (Spotify == null)
     {
         Spotify = new SpotifySessionListenerWrapper(_username, _password);
     }
     Spotify.MusicDataAvailable += OnMusicDataAvailable;
     Spotify.CheckBuffer        += OnCheckBuffer;
     MusicDataAvailable         += SpotifyWrapper_MusicDataAvailable;
     _currentState = SpotifyState.Initialized;
 }
Esempio n. 10
0
        /// <summary>
        /// Context changed.
        /// </summary>
        /// <param name="state"></param>
        /// <param name="withSkip"></param>
        /// <returns></returns>
        public static TransitionInfo ContextChange(
            [NotNull] SpotifyState state, bool withSkip)
        {
            var trans = new TransitionInfo(Reason.endplay,
                                           withSkip
                    ? Reason.clickrow
                    : Reason.playbtn);

            if (state.GetCurrentPlayable() != null)
            {
                trans.EndedWhen = state.GetPosition();
            }
            return(trans);
        }
Esempio n. 11
0
        public bool TryStartPlaylist(String playlistName, bool randomize)
        {
            _numberOfIterations = 0;
            if (_currentState == SpotifyState.Initialized)
            {
                LogIn();
            }
            bool returnVal = Spotify.TryStartPlaylist(playlistName, randomize);

            if (returnVal)
            {
                _currentState = SpotifyState.Playing;
            }
            return(returnVal);
        }
Esempio n. 12
0
        public IntentExecutor(
            ILogger <IntentExecutor> logger,
            BringState bringState,
            RouteState routeState,
            SpotifyState spotifyState,
            HueState hueState,
            WeatherState weatherState,
            CalendarState calendarState,
            FuelState fuelState,
            ClockState clockState,
            VvsState vvsState,
            FitbitState fitbitState,
            GoogleFitState googleFitState,
            SoccerState bundesligaState,
            NewsState newsState)
        {
            _logger          = logger;
            _bringState      = bringState;
            _routeState      = routeState;
            _spotifyState    = spotifyState;
            _hueState        = hueState;
            _weatherState    = weatherState;
            _calendarState   = calendarState;
            _fuelState       = fuelState;
            _clockState      = clockState;
            _vvsState        = vvsState;
            _fitbitState     = fitbitState;
            _googleFitState  = googleFitState;
            _bundesligaState = bundesligaState;
            _newsState       = newsState;

            _displayableDictionary = new Dictionary <Type, Displayable>
            {
                { typeof(BringState), bringState },
                { typeof(RouteState), routeState },
                { typeof(SpotifyState), spotifyState },
                { typeof(HueState), hueState },
                { typeof(WeatherState), weatherState },
                { typeof(CalendarState), calendarState },
                { typeof(FuelState), fuelState },
                { typeof(ClockState), clockState },
                { typeof(VvsState), vvsState },
                { typeof(FitbitState), fitbitState },
                { typeof(GoogleFitState), googleFitState },
                { typeof(SoccerState), bundesligaState },
                { typeof(NewsState), newsState },
            };
        }
Esempio n. 13
0
        public PlayerQueueEntry(
            [NotNull] ISpotifyDevice sink,
            [NotNull] IPlayableId playable,
            bool preloaded,
            [NotNull] IPlayerQueueEntryListener listener,
            int initialSeek)
        {
            this.sink       = sink;
            Playable        = playable;
            this.preloaded  = preloaded;
            this.listener   = listener;
            previousCommand = null;
            this.PlaybackId = SpotifyState.GeneratePlaybackId();
            _current        = playable;
            Debug.WriteLine($"Created new {this}");

            this.sink.PlaybackStateChanged += PlaybackSession_PlaybackStateChanged;
            this.sink.MediaOpened          += MediaPlayer_MediaOpened;
            this.sink.MediaEnded           += MediaPlayer_MediaEnded;
            listener.StartedLoading(this);
            _ = Load(preloaded, initialSeek);
        }
Esempio n. 14
0
        public void Initialize(Plugin plugin)
        {
            _plugin     = plugin;
            PlayerState = new PlayerStateStruct
            {
                ServiceName   = "Spotify",
                RequiresLogin = true
            };

            _spotifyState = new SpotifyState(_plugin.RemoteConfigManager.Config.SpotifyLoginUri, _plugin.RemoteConfigManager.Config.SpotifyClientId,
                                             _plugin.RemoteConfigManager.Config.SpotifyLoginPort, _plugin.RemoteConfigManager.Config.SpotifyPlayerRefreshTime);

            _spotifyState.OnLoggedIn          += OnLoggedIn;
            _spotifyState.OnPlayerStateUpdate += OnPlayerStateUpdate;

            if (_plugin.Configuration.SpotifySettings.TokenResponse == null)
            {
                return;
            }
            _spotifyState.TokenResponse = _plugin.Configuration.SpotifySettings.TokenResponse;
            _spotifyState.RequestToken();
            _startThread = new Thread(_spotifyState.Start);
            _startThread.Start();
        }
Esempio n. 15
0
 internal TracksKeeper(SpotifyState state)
 {
     _state = state;
     CheckComplete();
 }
Esempio n. 16
0
        void stateCheckTimer_Tick(object sender, EventArgs e)
        {
            // figure out what spotify is doing right now

            var iframes = browser.Document.GetElementsByTagName("iframe");

            foreach (Gecko.DOM.GeckoIFrameElement frame in iframes)
            {
                GeckoHtmlElement doc = null;

                string queryArtist = "", queryTrack = "", queryTrackUri = "", queryIsPlaying = "", queryAddButton = "", attrTrackUri = "";

                // Old Player
                if (frame.Id == "app-player")
                {
                    doc = frame.ContentDocument.DocumentElement as GeckoHtmlElement;

                    queryIsPlaying = "#play-pause.playing";
                    queryArtist    = "#track-artist a";
                    queryTrack     = "#track-name a";
                    queryTrackUri  = "#track-name a";
                    attrTrackUri   = "href";
                    queryAddButton = "#track-add";
                }
                // New Player
                if (frame.Id == "main")
                {
                    doc = frame.ContentDocument.DocumentElement as GeckoHtmlElement;

                    queryIsPlaying = "#play.playing";
                    queryArtist    = "p.artist a";
                    queryTrack     = "p.track a";
                    queryTrackUri  = "p.track a";
                    attrTrackUri   = "data-uri";
                    queryAddButton = ".caption button.button-add";
                }

                if (doc != null)
                {
                    SpotifyState oldState = currentSpotifyState;
                    string       oldTrack = currentTrack.TrackUri;

                    // get current track
                    var isPlaying = doc.QuerySelector(queryIsPlaying);
                    if (isPlaying != null)
                    {
                        currentSpotifyState = SpotifyState.Playing;
                        var artist   = doc.QuerySelector(queryArtist).TextContent;
                        var title    = doc.QuerySelector(queryTrack).TextContent;
                        var trackUri = doc.QuerySelector(queryTrackUri).GetAttribute(attrTrackUri);
                        currentTrack = new Mp3Tag(title, artist, trackUri);
                    }
                    else
                    {
                        currentSpotifyState = SpotifyState.Paused;
                    }

                    // ad detection (new player only)
                    var addToMyMusicButton = doc.QuerySelector(queryAddButton);
                    if (addToMyMusicButton != null)
                    {
                        var style = addToMyMusicButton.Attributes["style"];
                        if (style != null)
                        {
                            if (style.NodeValue.Contains("display: none"))
                            {
                                currentSpotifyState = SpotifyState.Ad;
                            }
                        }
                    }

                    // extra ad detection, works for old player too
                    if (currentTrack.Artist == "Spotify")
                    {
                        currentSpotifyState = SpotifyState.Ad;
                    }


                    // mute sound on ads
                    if (currentSpotifyState == SpotifyState.Ad)
                    {
                        if (MuteOnAdsCheckBox.Checked && !MutedSound)
                        {
                            addToLog("Ads detected - Attempting to Mute!");
                            Util.ToggleMuteVolume(this.Handle);
                            MutedSound = true;
                        }
                    }
                    else
                    {
                        if (MutedSound)
                        {
                            addToLog("Un-Muting");
                            Util.ToggleMuteVolume(this.Handle);
                            MutedSound = false;
                        }
                    }

                    // set state if changed
                    if (oldState != currentSpotifyState || oldTrack != currentTrack.TrackUri)
                    {
                        if (currentSpotifyState == SpotifyState.Playing)
                        {
                            var song = currentTrack.Artist + " - " + currentTrack.Title;
                            songLabel.Text = song;
                            addToLog("Now playing: " + song + " (" + currentTrack.TrackUri + ")");
                            if (_currentApplicationState != RecorderState.NotRecording && oldTrack != currentTrack.TrackUri)
                            {
                                ChangeApplicationState(RecorderState.Recording);
                            }
                            else if (_currentApplicationState == RecorderState.Recording)
                            {
                                ChangeApplicationState(RecorderState.WaitingForRecording);
                            }
                        }
                        else if (currentSpotifyState == SpotifyState.Paused)
                        {
                            addToLog("Music stopped");
                            if (_currentApplicationState == RecorderState.Recording)
                            {
                                ChangeApplicationState(RecorderState.WaitingForRecording);
                            }
                        }
                        else if (currentSpotifyState == SpotifyState.Ad)
                        {
                            addToLog("Ads...");
                            if (_currentApplicationState == RecorderState.Recording)
                            {
                                ChangeApplicationState(RecorderState.WaitingForRecording);
                            }
                        }
                    }

                    break;
                }
            }

            songLabel.Visible = _currentApplicationState == RecorderState.Recording;
        }
Esempio n. 17
0
 private void OnSpotifyStateChanged(SpotifyState previous, SpotifyState current) =>
     OnSpotifyStateChanged(new SpotifyStateChangedEventArgs(previous, current));
Esempio n. 18
0
 public SpotifyStateChangedEventArgs(SpotifyState previousState, SpotifyState newState) {
     PreviousState = previousState;
     NewState = newState;
 }