-3

I am currently having a probelm, where a file was sent to me as .m4a and I renamed it to .wav..... (I think that is the issue as I can play other .wav files)

Now it is giving me this error when I run the code:

Additional information: The file located at c:\Windows\Media\dj.wav is not a valid wave file.

Maybe I just need to change it back to .m4a and then have some website convert it to .wav compared to me just renaming it?

My code looks like this:

using System.Media;


playSimpleSound();



private void playSimpleSound()
    {
        SoundPlayer simpleSound = new SoundPlayer(@"c:\Windows\Media\dj.wav");
        simpleSound.Play();
    }

Also, how can I write my path, so that it would hit the file in the debug folder? Because I am going to deploy this to a thin client in another building.

Kyle Rickaby
  • 87
  • 2
  • 15

1 Answers1

1

Changing the extension of a file does not change the content in it. M4A are MPEG-4 audio-only data, whereas WAV files are typically raw and uncompressed audio samples.

To convert the data itself, you'll need to use an audio transcoding tool like SoX or GoldWave.

As for your path specifier, you can simply use "dj.wav" or "wavfiles\dj.wav", basically relative to where your exe sits. This is because the current working directory is set to where it resides when started with a simple double click in explorer. You can, however also specify the full path using the answer here.

Hope this helps!

Community
  • 1
  • 1
Ani
  • 10,482
  • 3
  • 22
  • 42