//*********************************************************************************************************************************************************************************************************** private async void PlayerApp_OnPlayerConnectionTokenExpired(object sender, PlayerConnectionTokenExpiredEventArgs e) { _logHandle.Report(new LogEventWarning("Connection token expired (was valid for " + e.ConnectionTokenExpirationTime.TotalSeconds.ToString() + " s).")); CurrentRecorder?.StopRecord(); bool wasMinimized = (ProcessHelper.GetProcessWindowState(PlayerApp.PlayerName).showCmd == WindowTheme.WindowPlacement.ShowWindowStates.Minimized); await((App)Application.Current).StartAndConnectToPlayer(wasMinimized); PlayerApp.IsConnectionTokenExpired = false; }
//*********************************************************************************************************************************************************************************************************** private void StartRecord() { PlayerApp.ListenForEvents = false; bool isPlaying = PlayerApp.CurrentPlaybackStatus.IsPlaying; OnPropertyChanged("AreRecorderSettingsChanged"); CurrentRecorder?.StopRecord(); if (!isPlaying || !IsRecorderArmed) //Only start a new record if music is playing and the recorder is armed { PlayerApp.ListenForEvents = true; return; } //if (Recorders.Count > 0 && Recorders.Select(r => r.TrackInfo.TrackID).Contains(PlayerApp.CurrentTrack.TrackID)) //{ // PlayerApp.ListenForEvents = true; // return; //} Recorder tmpRecorder = new SpotifyRecorderImplementierung((RecorderSettings)RecSettings.Clone(), PlayerApp.CurrentTrack, _logHandle); tmpRecorder.OnRecorderPostStepsFinished += TmpRecorder_OnRecorderPostStepsFinished; Recorders.Add(tmpRecorder); if (PlayerApp.CurrentTrack != null && !PlayerApp.CurrentPlaybackStatus.IsAd) { tmpRecorder?.StartRecord(); } CleanupRecordersList(); PlayerApp.ListenForEvents = true; }
//############################################################################################################################################################################################## private async void PlayerApp_OnTrackChange(object sender, PlayerTrackChangeEventArgs e) { //#warning TESTCODE //PlayerApp.CurrentPlaybackStatus.IsAd = true; //Use this for ad blocker testing if (PlayerApp.CurrentPlaybackStatus.IsAd) { _logHandle.Report(new LogEventInfo("Advertisement is playing")); } else { _logHandle.Report(new LogEventInfo("Track changed to \"" + e.NewTrack?.TrackName + "\" (" + e.NewTrack?.CombinedArtistsString + ")")); } bool blockAd = PlayerApp.CurrentPlaybackStatus.IsAd && IsPlayerAdblockerEnabled; if (blockAd) { CurrentRecorder?.StopRecord(); bool wasPlaying = PlayerApp.CurrentPlaybackStatus.IsPlaying; bool wasMinimized = (ProcessHelper.GetProcessWindowState(PlayerApp.PlayerName).showCmd == WindowTheme.WindowPlacement.ShowWindowStates.Minimized); if (wasPlaying) { PlayerApp.PausePlayback(); } if (blockAd) { await Task.Delay(300); await PlayerApp.ClosePlayerApplication(); await Task.Delay(1000); } await((App)Application.Current).StartAndConnectToPlayer(wasMinimized); await Task.Delay(1500); if (wasPlaying) { PlayerApp.ListenForEvents = false; if (blockAd) { PlayerApp.NextTrack(); } // after closing and reopening spotify opens with the last played track. So skip to the next track. Skipping already starts the playback. else { PlayerApp.StartPlayback(); } await Task.Delay(500); PlayerApp.ListenForEvents = true; PlayerApp.UpdateCurrentPlaybackStatus(); _logHandle.Report(new LogEventInfo("Track \"" + PlayerApp.CurrentTrack?.TrackName + "\" (" + PlayerApp.CurrentTrack?.CombinedArtistsString + ")")); StartRecord(); } else { PlayerApp.UpdateCurrentPlaybackStatus(); } } else { StartRecord(); } }