protected override void OnSpotifyStateChanged(object sender, SpotifyStateChangedEventArgs eventArgs) { base.OnSpotifyStateChanged(sender, eventArgs); var oldState = eventArgs.PreviousState; var newState = eventArgs.NewState; if (newState == SpotifyState.StartingUp || newState == SpotifyState.ShuttingDown) { return; } // we skip here as no audio session is present and muting would fail. if (oldState == SpotifyState.StartingUp && newState == SpotifyState.Paused) { return; } if (AggressiveMuting) { muter.SetMute(newState != SpotifyState.PlayingSong); return; } if (!WaitForAudioFade || oldState != SpotifyState.PlayingAdvertisement) { muter.SetMute(mute: newState == SpotifyState.PlayingAdvertisement); return; } if (newState == SpotifyState.PlayingAdvertisement) { muter.Mute(); return; } Task.Run(async() => { await Task.Delay(600).ConfigureAwait(false); muter.Unmute(); }); }
/// <summary> /// Unmutes the spotify audio session. /// </summary> /// <returns>A value indicating whether the operation was successful</returns> public static bool Unmute(this IMutingSpotifyHook muter) => muter.SetMute(false);
/// <summary> /// Mutes the spotify audio session. /// </summary> /// <returns>A value indicating whether the operation was successful</returns> public static bool Mute(this IMutingSpotifyHook muter) => muter.SetMute(true);