System.Media.SoundPlayer throws FileNotFoundException in .Net

369 Views Asked by At

trying to play a .wav file in my application for a preview.

-> following code is beeing executed:

System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = this.UnderlyingAudioFile.FullName;
player.Play();

Error occurs:
System.IO.FileNotFoundException: 'Please be sure a sound file exists at the specified location.'

this.UnderlyingAudioFile.FullName; Beeing a System.IO.FileInfo Object;

the path is definitely correct. I checked 3 times and can copy paste it from this.UnderlyingAudioFile.FullName;

1

There are 1 best solutions below

0
julian bechtold On BEST ANSWER

This Error actually occurs, when the other thread cannot access the File.

in my case, I had to open the file with fileshare.read property:

this.Reader = new BinaryReader(File.Open(path,FileMode.Open,FileAccess.Read,FileShare.Read));