Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trying to play .wav file which is in Resources folder, its there but visual studio sais it isn't!

I'm trying to play L1.wav which is in my resources folder. Previously I have pulled images from the resources file using the line btc.Properties.Resources.noImg which worked perfectly but if I try and do the same for the wav file I get a '...does not contain a definition for L1. Its there, works fine if I double click it. How do I get it to work?

System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = btc.Properties.Resources.L1;
player.play();

Thanks.

like image 260
flavour404 Avatar asked Oct 31 '10 21:10

flavour404


1 Answers

The SoundLocation property requires a string that contains a file path or a URL. The resource you added is however returned as a Stream if it was a .wav file. You should have gotten a compile error message, saying that it can't convert an UnmanagedMemoryStream to a string.

This code worked well on my machine:

        System.Media.SoundPlayer player = new System.Media.SoundPlayer();
        player.Stream = Properties.Resources.test;
        player.Play();

What btc means in your source code is quite mysterious and possibly the real source of the compiler error message you quoted.

like image 191
Hans Passant Avatar answered Sep 28 '22 05:09

Hans Passant