1

I use WMPLib to play .wav files:

var noteA0 = new WMPLib.WindowsMediaPlayer();
noteA0.URL = @"c:\sounds\piano\A0.wav";

For each note and button/key i have new instance. The problem is when i play 3-6 or even 7 instances at once, i play for some seconds and then sounds are gone... they just dissapeared, i press a key and can't hear anything but the keypress event is still sending message. When i wait some seconds and press a key, sounds are playing again...

Any idea what can i do?

Martin
  • 79
  • 10
  • WMPLib is an expensive component, when you create that many instances then your program is going to tank. Create only instance of the WindowsMediaPlayer() class. It is not otherwise suitable to implement a piano, google "c# create piano" for obvious hits. – Hans Passant Jun 28 '15 at 15:58

1 Answers1

0

If you need to play multiple files at once, try the System.Windows.Media.MediaPlayer class instead, and close each instance once you are done with it. You can also define a set number of instances and use them as channels, reusing instances that are no longer playing.

Drunken Code Monkey
  • 1,796
  • 1
  • 14
  • 18