/// <summary> /// Lowers the volume of the menu music, or stops playing it if the /// volume is unaudibly low. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> private void FadeMusic(GameTime gameTime) { if (!isMusicFading || themeSong == null) { return; } // Fade during 1 second float step = AudioMaster.GetVolume() * (float)gameTime.ElapsedGameTime.TotalSeconds; if (MediaPlayer.Volume > step) { MediaPlayer.Volume -= step; } else { MediaPlayer.Stop(); isMusicFading = false; } }
/// <summary> /// Attempts to start playing the menu music. /// </summary> private void PlayMusic() { if (MainClientConstants.OSId == OSVersion.WINVISTA) { return; // SharpDX fails at music playback on Vista } if (themeSong != null && UserINISettings.Instance.PlayMainMenuMusic) { musicVolume = 1.0f; isMusicFading = false; MediaPlayer.Volume = AudioMaster.GetVolume(); MediaPlayer.IsRepeating = true; try { MediaPlayer.Play(themeSong); } catch (InvalidOperationException ex) { Logger.Log("Playing main menu music failed! " + ex.Message); } } }