views:

636

answers:

3

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 apiori that it is not PCM and will not play, and block the file from being choosen.

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());
        }
A: 

wave files can be encoded differently(even with 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/

alexm
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) return;Another web site with format info:http://www.sonicspot.com/guide/wavefiles.htmlHad a bit more detail on formats.Thanks again for your help.
Mike
I'm glad it helped you.
alexm
A: 

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

MicrosoftProvider
A: 

Your file is not PCM. Please try http://alvas.net/alvas.audio.aspx

This library can play any wav-files. Simple code for playback see below

RecordPlayer rp = new RecordPlayer();

private void PlaySimple()
{
  string fileName = "play.wav";
  rp.Open(new DsReader(fileName));
  rp.Play();
}
ava