I was wondering if it's possible to play sound file (wav, mp3) from a Resource File. I need to play two sounds - one for background music (async in a loop), second one for a random sound. I tried SoundPlayer
, but BGM stops when I play a random sound (of course I use two separate SoundPlayers). So, I'm looking for a C# WPF Library which I can use to play two or more sounds in one time from Resources. I'd be grateful if somebody could provide an example. Thank You in advance.
-
1Duplicate question: stackoverflow.com/questions/15145209/…– RyanasSep 21, 2014 at 11:31
Add a comment
|
2 Answers
Have you tried using NAudio library? It is very easy and supports lots of functionalities.
-
I tried but without any effect. Maybe I wrote a bad code ;) Does NAudio support playing Resource file? If yes, how can I do that? Sep 21, 2014 at 11:39
I solved my problem with this code:
private NAudio.Wave.WaveFileReader wave = new NAudio.Wave.WaveFileReader(Properties.Resources.bgm);
private NAudio.Wave.DirectSoundOut outs = null;
public void PlayBGM()
{
if (outs == null)
{
outs = new NAudio.Wave.DirectSoundOut();
outs.Init(new NAudio.Wave.WaveChannel32(wave));
}
outs.Play();
}