0

How can I play sound effects in a game created with the universal app template (so it runs on both Windows 8.1 and Windows Phone 8.1) programmatically?

I need to play the sound from a GameManager class I've created.

juliano.net
  • 7,982
  • 13
  • 70
  • 164
  • http://msdn.microsoft.com/en-us/library/windows/apps/dn263233.aspx – IL_Agent Jun 27 '14 at 12:06
  • Sorry but I've said programmatically. From C# only. – juliano.net Jun 27 '14 at 12:08
  • maybe this ? http://stackoverflow.com/questions/19591131/does-a-mediaelement-only-play-when-it-is-embedded-in-xaml-code – IL_Agent Jun 27 '14 at 12:14
  • For the love of god... PLEASE don't use media element to play sound effects in a game lol.... – DotNetRussell Jun 27 '14 at 15:10
  • @AnthonyRussell what do you suggest? – juliano.net Jun 27 '14 at 15:35
  • There are a couple options that are better. I would start with this post on how to hack XNA into Windows 8. It has a sound effect object that is WAY better than media element. http://stackoverflow.com/questions/12849107/how-to-install-the-xna-game-studio-4-0-in-windows-8 If you want a more conventional way then look at sharpdx. Media element is not made for games. It has high over head and is buggy when you try and use it in the manner you are suggesting. – DotNetRussell Jun 27 '14 at 15:55
  • @AnthonyRussell, do you have a sample using sharpdx? – juliano.net Jun 28 '14 at 03:05

1 Answers1

0

Note that MediaElement is designed mostly to play a single audio track so you'd need to manage a pool of these to play more than one at a time and also its latency might not be low enough. I'd look into XAudio2 if you'd be OK with some C++ or its SharpDX wrapper for C# or just use MonoGame's SoundEffect class that makes things easy.

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
  • Do you know any tutorial or sample for SharpDX? Their GitHub repository says that the samples are outdated. – juliano.net Jun 28 '14 at 02:27
  • Sorry, not really. That's one of my main problems of using SharpDX vs. native DX. However limited the official DX documentation might be - there are still tons more documentation and samples available for that. I'd try bingoogling for "Audio2 SharpDX" or looking at the native documentation and finding similar SharpDX versions. Another option is looking at MonoGame sources which I think might be using SharpDX. – Filip Skakun Jun 29 '14 at 04:35