views:

226

answers:

2

My wave won't play under debug. If I hit CTRL+F5 I get a nice WAV and the Console writes out the file cursor position (buf.PlayPosition) and then the method exits when the sound is over. Under debug (when I just hit F5) there is no audio output, however the file cursor position is still increased in the console window and the method exits without exception.

using Microsoft.DirectX.DirectSound;

public void Play()
    {
        var fileName = "bass.wav";
        using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
        {       
            using (var dev = new Device())
            {
                dev.SetCooperativeLevel(this, CooperativeLevel.Priority);
                using (Buffer buf = new Buffer(stream, dev))
                {
                    buf.Volume = 0;
                    buf.Play(0, BufferPlayFlags.Default);
                    while (buf.Status.Playing)
                    {
                        System.Console.WriteLine("playing " + buf.PlayPosition);
                    }
                }
            }
        }
    }

Any ideas?

+1  A: 

Maybe you need to give the buffer "Global Focus" using the BufferDescription. From the C++ Docs:

"The DSBCAPS_GLOBALFOCUS flag in the example ensures that the buffer will continue playing even when the application window is not in the foreground. Without this flag, the buffer will be muted when another application or even a dialog box has the input focus."

Try using the public SecondaryBuffer(Stream, BufferDescription, Device); form of the constructor.

AShelly
What's the benefit of using a SecondaryBuffer over using a Buffer?
runrunraygun
A: 

I disabled the Visual Studio Hosting Process and this seems to have fixed the problem.

runrunraygun