private async Task OnSpotifyConnected(SpotifyStateEventArgs e) { if (logger.IsDebugEnabled) { StringBuilder sb = new StringBuilder(); sb.Append("Spotify Connected. Status = {") .Append($" CurrentSong: {(e.CurrentSong != null ? $"\"{e.CurrentSong}\"" : "null")},") .Append($" Playing: {e.Playing},") .Append($" TrackTime: {e.TrackTime},") .Append($" Volume: {e.Volume}") .Append(" }"); logger.Debug(sb.ToString()); } this.IsPlaying = e.Playing; this.CurrentSong = e.CurrentSong; this.Connected?.Invoke(this, e); if (Settings.Current.EnableBroadcaster) { await this.Broadcaster.StartAsync().ConfigureAwait(false); await this.Broadcaster.BroadcastPlayState(e.Playing).ConfigureAwait(false); await this.Broadcaster.BroadcastCurrentSong(e.CurrentSong).ConfigureAwait(false); } }
private async Task OnSpotifyConnected(SpotifyStateEventArgs e) { if (logger.IsDebugEnabled) { StringBuilder sb = new StringBuilder(); sb.Append($"Spotify Connected. Status = {{{Environment.NewLine}") .Append($" CurrentSong: {(e.CurrentTrack != null ? $"\"{e.CurrentTrack}\"" : "null")},{Environment.NewLine}") .Append($" Playing: {e.Playing},{Environment.NewLine}") .Append($" TrackTime: {e.TrackTime},{Environment.NewLine}") .Append($" Volume: {e.Volume}{Environment.NewLine}") .Append("}"); logger.Debug(sb.ToString()); } this.IsPlaying = e.Playing; this.CurrentTrack = e.CurrentTrack; this.Connected?.Invoke(this, e); if (Settings.Current.EnableSpotifyWebApi) { this.DisposeWebApiInitializer(); this.webApiInitCancellationTokenSource = new CancellationTokenSource(); this.BeginInitializeWebAPI(); } if (Settings.Current.EnableBroadcaster) { await this.Broadcaster.StartAsync().ConfigureAwait(false); await this.Broadcaster.BroadcastPlayState(e.Playing).ConfigureAwait(false); await this.Broadcaster.BroadcastCurrentTrack(e.CurrentTrack).ConfigureAwait(false); } }
private static void Spotify_Connected(object sender, SpotifyStateEventArgs spotifyStateEventArgs) { // Show the changelog if necessary if (!string.IsNullOrWhiteSpace(previousVersion)) { Version previous = new Version(previousVersion); if (previous < new Version(App.CurrentVersionNoRevision)) { ChangelogView.Launch(); } } }
private async void SpotifyWindow_InitializationFinished(object sender, EventArgs e) { try { this.spotifyWindow.InitializationFinished -= this.SpotifyWindow_InitializationFinished; if (this.spotifyWindow.IsValid) { this.spotifyWindow.TitleWatcher.TitleChanged += this.SpotifyWindowTitleWatcher_TitleChanged; // Fake the Connected event string currentTitle = this.spotifyWindow.Title; SpotifyStateEventArgs spotifyStateEventArgs; if (SpotifyWindow.PausedTitles.Contains(currentTitle, StringComparer.InvariantCulture)) { spotifyStateEventArgs = new SpotifyStateEventArgs(null, false, 1.0, 1.0); } else { Song newSong = Song.FromSpotifyWindowTitle(currentTitle); spotifyStateEventArgs = new SpotifyStateEventArgs(newSong, true, 1.0, 1.0); } await this.OnSpotifyConnected(spotifyStateEventArgs).ConfigureAwait(false); } else { string logError = this.spotifyProcess.HasExited ? "process has been terminated" : "null handle"; logger.Fatal($"Couldn't find Spotify's window: {logError}"); string errorMsg = Resources.ERROR_STARTUP_SPOTIFY_WINDOW_NOT_FOUND; MessageBox.Show($"{errorMsg}", "Toastify", MessageBoxButton.OK, MessageBoxImage.Error); App.Terminate(); } } catch (Exception exception) { logger.Error($"Unhandled exception in {nameof(this.SpotifyWindow_InitializationFinished)}.", exception); } }
private async void Spotify_Connected(object sender, SpotifyStateEventArgs e) { await this.OnSpotifyConnected(e).ConfigureAwait(false); }
private void Spotify_Connected(object sender, SpotifyStateEventArgs e) { this.Connected?.Invoke(sender, e); }