public void Spotify_StateChanged(object sender, StateChangedEventArgs e) { addToLog("Change detected"); currentDeezerState = e.State; currentTrack = e.Song; if (e.State == DeezerState.Playing) { string song = e.Song.ToString(); songLabel.Text = song; addToLog("Now playing: " + song); // If we are monitoring, set the state to recording if (_currentApplicationState == RecorderState.WaitingForRecording) { ChangeApplicationState(RecorderState.Recording); } // If we are already recording, stop the recording and restart it. else if (_currentApplicationState == RecorderState.Recording) { ChangeApplicationState(RecorderState.WaitingForRecording); ChangeApplicationState(RecorderState.Recording); } } else if (e.State == DeezerState.Paused) { addToLog("Music paused or stopped"); // If we were recording a song, now we aren't anymore if (_currentApplicationState == RecorderState.Recording) { ChangeApplicationState(RecorderState.WaitingForRecording); } } }
public async Task SongChange(DeezerState deezerState) { if (File.Exists("deezer.json")) { var lastSong = _playerFactoryService.GetCurrentSongInfo(); if ((DateTime.UtcNow - lastSong.LastModifed) > TimeSpan.FromMinutes(1)) { await _lastFMService.StartScrobble(new SongDetails { Album = lastSong.Album, Song = lastSong.Song, Artist = lastSong.Artist }); } } var context = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <ServerHub>(); if (context == null) { return; } var pandoraInfo = new PandoraResult { Album = deezerState.AlbumName, AlbumUri = deezerState.AlbumUri, Artist = deezerState.ArtistName, IsPlaying = deezerState.IsPlaying, LastModifed = deezerState.UpdatedUtc, Loved = false, Radio = deezerState.StreamName, Song = deezerState.SongName }; RabbitMqService.SongChange(pandoraInfo); context.Clients.All.pandoraRefresh(pandoraInfo); var song = new SongDetails() { Album = pandoraInfo.Album, Artist = pandoraInfo.Artist, Song = pandoraInfo.Song }; await _lastFMService.UpdateNowPlaying(song); var json = JsonConvert.SerializeObject(deezerState); File.WriteAllText("deezer.json", json, Encoding.UTF8); }
void stateCheckTimer_Tick(object sender, EventArgs e) { DeezerState oldState = currentDeezerState; Mp3Tag oldTrack = new Mp3Tag(currentTrack.Title, currentTrack.Artist); // figure out what Deezer is doing now // therefore, we need to execute a small javascript code // which returns all HTML elements with a specific tag // the first element of these gives us the song title // the next elements give us the artists // Get this array string script = "[dzPlayer.getSongTitle(), dzPlayer.getArtistName()]"; try { mainBrowser.EvaluateScriptAsync(script).ContinueWith(x => { var response = x.Result; if (response.Success && response.Result != null) { var list = (List <object>)response.Result; string artist = list[1].ToString(); string title = list[0].ToString(); //currentTrack = new Mp3Tag(title, artist); this.Invoke((Action)(() => { //currentTrack = new Mp3Tag(title, artist); Mp3Tag newTag = new Mp3Tag(title, artist); if (!(newTag.Equals(currentTrack))) { StateChanged(this, new StateChangedEventArgs() { Song = newTag, PreviousSong = currentTrack, State = currentDeezerState, PreviousState = currentDeezerState }); } })); } }); } catch (Exception ex) { addToLog("Error: " + ex.Message); } // Find out if Deezer is paused or playing string scriptIsPlaying = "dzPlayer.isPlaying()"; try { mainBrowser.EvaluateScriptAsync(scriptIsPlaying).ContinueWith(y => { var responseIsPlaying = y.Result; if (responseIsPlaying.Success && responseIsPlaying.Result != null) { bool isPlaying = (bool)responseIsPlaying.Result; if (isPlaying) { this.Invoke((Action)(() => { if (currentDeezerState != DeezerState.Playing) { StateChanged(this, new StateChangedEventArgs() { PreviousState = currentDeezerState, State = DeezerState.Playing, Song = currentTrack, PreviousSong = currentTrack }); } })); } else { this.Invoke((Action)(() => { if (currentDeezerState != DeezerState.Paused) { StateChanged(this, new StateChangedEventArgs() { PreviousState = currentDeezerState, State = DeezerState.Paused, Song = currentTrack, PreviousSong = currentTrack }); } })); } } }); } catch (Exception ex) { addToLog("Error: " + ex.Message); } }