none
How to I change XNA Playback device at runtime RRS feed

  • Question

  • I have a test app that runs on Win7 with sounds and I'm using XNA for audio playback.
    It's as simple as:

    SoundEffect soundEffect; = SoundEffect.FromStream("c:\soundFile.wav");
    SoundEffectInstance soundEffectInstance = soundEffect.CreateInstance();
    soundEffectInstance.IsLooped = true;
    soundEffectInstance.Play();

    This plays the sound in loop and I can hear it on my speakers (default playback device).

    Now I change my default playback device from Speaker to Headphone.
    So with Windows SoundProperties under the Playback tab, I can "Set as default
    device" my headphone but the sounds still output only to my
    Speakers.  However, if I use MediaPlayer to open another wave file, it does play to the Headphone.
    If I restart the test app, it then output to the headphone.

    So how do I make my app change the audio output to the new "Default playback device" without restarting?

    Friday, March 30, 2012 3:02 PM

Answers

  • I chased down the answer with the XNA team, and have posted it in the other forum.  I am cross posting here, since the question was also asked here... In the future, that forum is a better place to post XNA questions. :)

    Short answer is that you cannot do this with SoundEffect.  The SoundEffect engine uses whatever the default output device is at the time that it is instantiated and sticks with that device throughout. 

    However, if you use XACT and AudioEngine then there should be a way for you to do this with AudioEngine.  First construct an audio engine and then look at the renderer details.  It should list all the output devices.  After that, construct another audio engine using the 2<sup>nd </sup>overload and pass in a specific renderer ID (from the ID’s listed). 

    FYI – This is something we shipped in XNA GS 3.1 and it hasn’t been touched since so it should still work but I'm not sure if there are any gotcha’s to worry about.


    Thursday, April 5, 2012 10:11 PM

All replies

  • try stopping playback (stop the loop) then restart the playback loop.
    • Proposed as answer by ChrisCicc Saturday, March 31, 2012 9:44 PM
    • Unproposed as answer by vuloc_nguyen Monday, April 2, 2012 3:56 PM
    Saturday, March 31, 2012 9:44 PM
  • I tried that (Stop an play again), it still try output to the same output device.

    I even tried to create a new soundEffectInstance and then play it ... with the same result.

    Any other idea of what I can try?

    Monday, April 2, 2012 3:52 PM
  • Since this is a basic XNA question, and not related to Kinect, you will likely have better luck in the XNA audio forum.  By happenstance, someone posted exactly this question a couple of days ago.  It is not answered there yet, but that is a location the XNA team will be monitoring, and will be able to provide the answer.

    http://forums.create.msdn.com/forums/t/102228.aspx

    Tuesday, April 3, 2012 12:17 AM
  • I chased down the answer with the XNA team, and have posted it in the other forum.  I am cross posting here, since the question was also asked here... In the future, that forum is a better place to post XNA questions. :)

    Short answer is that you cannot do this with SoundEffect.  The SoundEffect engine uses whatever the default output device is at the time that it is instantiated and sticks with that device throughout. 

    However, if you use XACT and AudioEngine then there should be a way for you to do this with AudioEngine.  First construct an audio engine and then look at the renderer details.  It should list all the output devices.  After that, construct another audio engine using the 2<sup>nd </sup>overload and pass in a specific renderer ID (from the ID’s listed). 

    FYI – This is something we shipped in XNA GS 3.1 and it hasn’t been touched since so it should still work but I'm not sure if there are any gotcha’s to worry about.


    Thursday, April 5, 2012 10:11 PM