-3

I'm trying to pass the file location from my list box into my sound player.

string fileLocation = listBox1.ToString();
SoundPlayer splayer = new SoundPlayer(soundLocation: fileLocation);
splayer.Play();

debugging shows the variable coming through as "C:\Temp\Sample1.wav".

The error comes back as "System.NotSupportedException: 'The given path's format is not supported.'"

Can anyone tell me what I'm doing wrong here?

TuckRollworthy
  • 105
  • 2
  • 9
  • 1
    Is there a question here? What is the problem you're running in to? It looks like you're already passing the file path as a string in to the constructor successfully. – tnw Sep 22 '21 at 19:51
  • sorry i missed a bit off :-) – TuckRollworthy Sep 22 '21 at 20:55
  • Sounds like the file path string isn't formatted properly and/or has some funky characters that aren't supported. https://stackoverflow.com/questions/7348768/the-given-paths-format-is-not-supported – tnw Sep 22 '21 at 21:01
  • @tnw thanks so much that looks like the issue. I'll try it out – TuckRollworthy Sep 23 '21 at 14:16
  • @tnw thanks mate, your direction wasn't quite what I needed. But it directed me in the right direction. – TuckRollworthy Sep 25 '21 at 06:59

1 Answers1

0

cracked it! you need to pull the object then convert it to a string.

        object fileLocationobj = listBox1.Items[0];
        string fileLocation = fileLocationobj.ToString(); 
        SoundPlayer splayer = new SoundPlayer(soundLocation: fileLocation);
        splayer.Play()
TuckRollworthy
  • 105
  • 2
  • 9
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 24 '21 at 00:00