public NewSessionIdEvent( [NotNull] String sessionId, [NotNull] SpotifyState state) { this.sessionId = sessionId; this.state = state; }
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(); }
public void LogIn() { if (_currentState == SpotifyState.Initialized) { Spotify.LogIn(); _currentState = SpotifyState.LoggedIn; } }
/// <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); }
public void StopMusic() { if (_currentState == SpotifyState.Playing) { _currentState = SpotifyState.LoggedIn; Spotify.StopMusic(); StopStream(_streamKey); LogOut(); _provider = null; } }
/// <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); }
public void LogOut() { if (_currentState == SpotifyState.Playing) { StopMusic(); } if (_currentState == SpotifyState.LoggedIn) { Spotify.LogOut(); _currentState = SpotifyState.Initialized; } }
/// <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); }
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; }
/// <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); }
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); }
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 }, }; }
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); }
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(); }
internal TracksKeeper(SpotifyState state) { _state = state; CheckComplete(); }
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; }
private void OnSpotifyStateChanged(SpotifyState previous, SpotifyState current) => OnSpotifyStateChanged(new SpotifyStateChangedEventArgs(previous, current));
public SpotifyStateChangedEventArgs(SpotifyState previousState, SpotifyState newState) { PreviousState = previousState; NewState = newState; }