Playing a sound in DirectX9 from Non active window (VB.NET2005)
  Home FAQ Contact Sign in
microsoft.public.win32.programmer.directx.audio only
 
Advanced search
POPULAR GROUPS

more...

microsoft ... directx.audio Profile…
 Up
Playing a sound in DirectX9 from Non active window (VB.NET2005)         


Author: Rick Muething
Date: Sep 18, 2008 09:05

I have what should be a simple problem but haven't been able to find a
solution.
I am using DirectX 9 to play a simple 16 bit mono sound file in a Sound card
modem application. The playback code is simple:
devSelectedPlaybackDevice.SetCooperativeLevel(Me.Handle,
CooperativeLevel.Priority)
bufPlayback = New SecondaryBuffer(Filename,
devSelectedPlaybackDevice)
bufPlayback.Volume = -5000 + 50 * intOutputLevel ' -5000=off,
0=full volume
bufPlayback.Play(0, BufferPlayFlags.Default)

All this works fine IF the application window is the active window. If the
application
Window is not the active window the sound card capture code (not shown)
continues to work fine but there is no playback from the sound card output.
This works the same way on several different sound cards (internal or
external USB). There is no exception thrown just no output from the sound
card. Once the window containing the application is made active again it
plays correctly.
Show full article (1.17Kb)
3 Comments
Re: Playing a sound in DirectX9 from Non active window (VB.NET2005)         


Author: Chris P.
Date: Sep 18, 2008 09:18

On Thu, 18 Sep 2008 09:05:01 -0700, Rick Muething wrote:
> All this works fine IF the application window is the active window. If the
> application
> Window is not the active window the sound card capture code (not shown)
> continues to work fine but there is no playback from the sound card output.
> This works the same way on several different sound cards (internal or
> external USB). There is no exception thrown just no output from the sound
> card. Once the window containing the application is made active again it
> plays correctly.

Add GlobalFocus to your BufferDescription.Flags.

--
http://www.chrisnet.net/code.htm
[MS MVP for DirectShow / MediaFoundation]
no comments
Re: Playing a sound in DirectX9 from Non active window (VB.NET2005         


Author: Rick Muething
Date: Sep 18, 2008 10:21

Chris,
That sounds like it should do the trick. But I am having problems with the
exact syntax and commands to set the GlobalFocus flag for the buffer.
Can you prompt me with the sequence of actual commads to set the buffer
flags and create the buffer with the global focus?

Thanks

--
Rick Muething
Winlink Development Team

"Chris P." wrote:
Show full article (1.07Kb)
no comments
Re: Playing a sound in DirectX9 from Non active window (VB.NET2005         


Author: Chris P.
Date: Sep 18, 2008 11:13

On Thu, 18 Sep 2008 10:21:01 -0700, Rick Muething wrote:
> That sounds like it should do the trick. But I am having problems with the
> exact syntax and commands to set the GlobalFocus flag for the buffer.
> Can you prompt me with the sequence of actual commads to set the buffer
> flags and create the buffer with the global focus?

I haven't used the managed interfaces but it looks like you want the other
constructor that allows you to pass the BufferDescription as the second
parameter. There may be a problem however if the BufferDescription.Format
you create doesn't match the WaveFormat from the file, that part will have
to be tested.

wFormat = new WaveFormat()
wFormat.AverageBytesPerSecond = 'read these values from file
wFormat.BitsPerSample =
wFormat.BlockAlign =
wFormat.Channels =
wFormat.FormatTag = WaveFormatTag.Pcm
wFormat.SamplesPerSecond =

BuffDesc = new BufferDesc(wFormat)

devSelectedPlaybackDevice.SetCooperativeLevel(Me.Handle, CooperativeLevel.Priority)
Show full article (1.28Kb)
no comments