Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was able to reproduce a similar issue (for me the Game window will actually hang and become unresponsive) in a new Game project using the code you posted above.</p> <p>I was also able to find forum posts from others experiencing similar issues (from as long as two years ago like this one -> <a href="http://forums.create.msdn.com/forums/t/45296.aspx" rel="nofollow">http://forums.create.msdn.com/forums/t/45296.aspx</a> ). This is apparently a bug in the framework.</p> <p>I'm not exactly sure what might be going on. I'm guessing that there's some funkiness happening with checking the MediaPlayer which might be stealing window focus away and then coming back to the game which returns focus so that for split milliseconds the game is losing and gaining focus so the music is Pausing Resuming Pausing over and over again at 60 times per second. On weaker machines like mine it causes the window to become un-responsive. That's all just conjecture since I don't know for sure, but it makes sense.</p> <p>I was able to work around the issue however by simply cutting the MediaPlayer state check out of the equation. If you have your own boolean flag that you add to the game (something like "isPlaying) and then query that boolean variable instead of checking the MediaPlayer state, the issue clears up and you get the functionality you desire. </p> <p>The code would look something like below.</p> <pre><code>bool isMusicPlaying = false; protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); Song song = Content.Load&lt;Song&gt;("SampleSong"); MediaPlayer.Play(song); isMusicPlaying = true; } protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); if (!IsActive &amp;&amp; isMusicPlaying == true) { MediaPlayer.Pause(); isMusicPlaying = false; } else if (IsActive &amp;&amp; isMusicPlaying == false) { MediaPlayer.Resume(); isMusicPlaying = true; } base.Update(gameTime); } </code></pre> <p>With the above code you should still get the original functionality you were looking for while getting rid of the un-desired behavior that was occurring using MediaPlayer's built in state.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload