The following code works with some wav files, but with the others I get, "InvalidOperationException was unhandled. Message = Sound API only supports playing files in PCM format."
var webClient = new WebClient(); webClient.DownloadFile(url, fileName); var fileSound = new SoundPlayer(fileName); fileSound.PlaySync();
Is there a way to programmatically check if the wav file is "bad" (and not a PCM wave file) and then convert it as needed?
What is strange is that the code works in an outdated Delphi application - all wav files play just fine. Here's the Delphi code:
filename := GetEnvironmentVariable('TEMP')+'\archieAndDingbat.wav'; URLDownloadToFile(nil, PChar(url), PChar(filename), 0, nil); PlaySound(filename);
I looked at the properties of the two files in Explorer and I see that there is a difference. For a file that is being played, its audio format is PCM; what will not play is CCITT u-Law.
So ... I either need a way to convert from CCITT u-Law to PCM on the fly after downloading these files (they are downloaded from a URL and then played locally), or maybe another way to play these files is PlaySync () ...
source share