views:

28

answers:

1

Hi,

I am (after some strangeness with my resources file) able to play a .wav file in my project:

SoundPlayer player = new SoundPlayer();
player.Stream = Sounds.L1;
Player.Play();

This works fine but what I want to do is be able to concatenate a string together and then call the file. The .wav filename would be of the form "L" + int, with int being anywhere between 1 - 99 i.e. L1, L2...L99. All the different sound files are in a resx file title Sounds.

How would I be able to call them?

I am trying to use the ResXResourceSet resxSet = new ResXResourceSet("btc.Sounds") ResXResourceSet to load the resources file and then use the .getobject() as suggested. However, how do you specify the location of the embedded resource file? If I use a path as above I get an error as it is looking in my bin/debug folder, which is where the .exe is placed. If I explicityly specify the path I get an access error and one thing I am really curious about is the fact that the 'Sounds.resx' file is an embedded resource so it should 'know' where it is and shouldn't need any path... I have tried pretty much every permutation including using Assembly.GetExecutingAssembly().GetManifestResourceStream("btc_I_Cap.Sounds"), @"....\Sounds" @"....\Resources", @"btc.Sounds" "Sounds.resx" and so on and so far nothing. Can someone please put me out of my misery so that I can go 'oh yeah, that was obvious why didn't I think of that!'

Happy halloween.

Thanks.

+1  A: 

Use a ResXResrouceSet to call the sound file Something like this:

using (ResXResourceSet resxSet = new ResXResourceSet(resxFile))
{
    for (int i = 1; i <= 99; i ++)
    {
        SoundPlayer simpleSound = (SoundPlayer)resxSet.GetObject("L" + i.ToString());
        simpleSound.Play();
    }
}
James Santiago
ResXResourceSet resxSet = new ResXResourceSet(Sounds). This gave me an error so obviously I am misunderstanding something. Sounds being the resources file in which all the .wav files are being kept.Sais it is a type but is being used like a variable.
flavour404