Skip to content

Instantly share code, notes, and snippets.

@jcbozonier
Created October 3, 2009 09:33
Show Gist options
  • Select an option

  • Save jcbozonier/200539 to your computer and use it in GitHub Desktop.

Select an option

Save jcbozonier/200539 to your computer and use it in GitHub Desktop.
public void PlaySound(string fileName)
{
IntPtr handle = IntPtr.Zero;
_Element.Dispatcher.Invoke(((Action)(() =>
{
handle = ((HwndSource) PresentationSource.FromVisual(_Element)).Handle;
})));
var device = new Device(DSoundHelper.DefaultPlaybackDevice);
device.SetCooperativeLevel(handle, CooperativeLevel.Normal);
using (var buffer = new VorbisBuffer(fileName, device, false, VorbisCaps.None))
{
buffer.Play(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment