Note that there are some explanatory texts on larger screens.

plurals
  1. POI'm seeing strange behavior in XNA when using MediaPlayer
    text
    copied!<p>In XNA I'm using MediaPlayer to play my music. I found that when playing the release build (run as the executable, not from Visual Studio) the game window would sometimes flicker and seem like it was trying to minimize and then come back. Sometimes the game icon on the task bar will appear a bit to the side and slide back to where it is. I'm using Windows 7. It was easy to reproduce by starting the game, making an explorer window the active window, leaving it for a second or two, then clicking on the game. It takes about 6-10 seconds for the game window to twitch, but then it happens about every 4-8 seconds after that. </p> <p>I hunted down what exactly was causing this, and it is the following code, being called through the main game update.</p> <pre><code>if (!IsActive &amp;&amp; MediaPlayer.State != MediaState.Paused) { MediaPlayer.Pause(); } if (IsActive &amp;&amp; MediaPlayer.State == MediaState.Paused) { MediaPlayer.Resume(); } </code></pre> <p>Basically, I'm pausing the music when the game isn't active, and unpausing when the game is active again. For some reason this is messing things up. I've tried just muting the music instead of pausing but I get the same effect. I made a new PC XNA 4.0 game, but even with only the above code (and the base.Update) in the main update function it still happens so it is definitely the code that's causing the problem. Does anyone know what is going on here, or another way to pause the music when the game goes inactive?</p>
 

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