0

When I try to play the sound file "Windows Critical Stop.wav" I get the following exception: exec {"Sound API only supports playing PCM wave files."} System.Exception {System.InvalidOperationException}

I understand what PCM is, I just do not know how to either: 1) play the sound file, 2) determine a priori that it is not PCM and will not play, and block the file from being chosen.

Here is the code I am using:

SoundPlayer player = new SoundPlayer();
player.SoundLocation = FileNameTextBox.Text;

try
{
    player.Play();
}
catch (Exception exec)
{
    MessageBox.Show("Sound could not be played: " + exec.ToString());
}
Zach Johnson
  • 23,678
  • 6
  • 69
  • 86

2 Answers2

2

Wave files can be encoded differently (even with the GSM codec), so just examine what codec is used to skip a particular one. Just check the AudioFormat bits.

https://ccrma.stanford.edu/courses/422/projects/WaveFormat/

Zach Johnson
  • 23,678
  • 6
  • 69
  • 86
oldUser
  • 243
  • 2
  • 12
  • Thanks that helped. The file in question had a 0x55 in that field. For any curious I put in the following code: if (dialog.ShowDialog() == DialogResult.OK) { BinaryReader br = new BinaryReader(File.Open(dialog.FileName, FileMode.Open)); br.BaseStream.Position = 20; Int16 aF = br.ReadInt16(); br.Close(); if ((aF != 1) && (aF != 2)) { MessageBox.Show("Bad Audio format = " + audioFormat.ToString()); return; Another web site with format info: http://www.sonicspot.com/guide/wavefiles.html Had a bit more detail on formats. Thanks again for your help. –  Dec 28 '09 at 02:46
  • This program can convert your files to PCM. Just uncheck the adware crap and it's free: http://www.nch.com.au/switch/ – Sire May 03 '12 at 09:42
-1

You have to use this player the code you have is a system damager Microsoft admin,