The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

WP7 XNA MediaPlayer interferes with MediaElement and custom MediaStreamSource RRS feed

  • Question

  • In my Windows Phone 7 app I'm using a custom MediaStreamSource to produce custom audio samples in real time to a MediaElement. I'm wiring this up with MediaElement.SetSource(MediaStreamSource).

    I need to check to see if the XNA/WP7 MediaPlayer is currently playing a song from the music library and stop it first (one of Microsoft's certification requirements). The problem is that if I make any call to the XNA MediaPlayer class, my MediaStreamSource is not called for any samples. the XNA MediaPlayer can even be in a Stopped state to cause the problem. If I remove all MediaPlayer calls, the code works fine. I am using a FrameworkDispatcher in both cases.

    Here is the problematic code:

    var state = MediaPlayer.State;

    Notice that I don't even have to do anything with the MediaPlayer. In the code above I just get the MediaPlayer's State value - I'm merely calling a getter on a property. If the MediaPlayer is stopped and I simply get a property value from it, the MediaStreamSource does not work.

    Here is code that DOES work:


    It's as if something within the XNA media library hijacks the MediaElement as soon as you start using it. Any thoughts?

    Wednesday, December 1, 2010 2:55 PM

All replies

  • The problem only appears to happen when a debugger is attached. Without the debugger I cannot reproduce the problem.
    Wednesday, December 1, 2010 5:21 PM
  • Instead of using the State property have you tried the GameHasControl property? That's the correct way to see if the user is listening to music (if it returns false, it means the user is listening to media library music).

    Is this in the emulator or on a device? Are you using the Windows Phone Connect tool at all:
    Wednesday, December 1, 2010 6:06 PM