R
raylopez99
I have the latest version of Visual Studio 2008 Professional, which
allows you to create resource files (this is the .resx file, no?),
unlike the Express version, which does not.
I am trying to cut and paste code that MSDN recommends for playing a
simple wav file from inside an embedded file, like presumeably the
'resources' file .resx is. I want to embed the .wav file in a
'resource file' since I don't want the user storing the file on their
hard drive.
Using the Wizard, and clicking on various links, I was able to create
a resource file (.resx file?) that plays a small sound, 25 kb, that I
call "mywav.wav" (it plays this sound when you click on the icon for
the audio file in Visual Studio, in the .resx file and accompanying
files*). The .resx file only has this wav in it, nothing else, and
the .resx resource file is called "myaudio.resx".
I used the below code, which is pretty generic, but I cannot get
anything but a small 'ding' (which I think is the default Windows
error sound), but not the sound of "mywav.wav". I tried various
permutations of the string. Apparently this ADO.NET type language is
not strongly typed since it compiles with no problems, but it doesn't
run right...what is wrong?
RL
* I notice the .resx file is in XML format and contains a string for a
"PublicKeyToken". Perhaps, since I've never used this before, I need
to somehow log in for Visual Studio under my Administrator account (I
am using XP as the OS), and reset something?
//a class method declared and used inside of form Form 1, from an
object instantiated as "myClassObject"
public void playSoundFromResource(object sender, EventArgs e)
{
System.Reflection.Assembly a =
System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream s =
a.GetManifestResourceStream("<myaudio.resx>.mywav.wav"); //<--note
string--is this correct?
SoundPlayer player = new SoundPlayer(s);
player.Play();
}
// I use it on a button in Form form 1--when I click on a button, the
mywav.wav does not play, but a small 'ding' does...why?
private void button1_Click(object sender, EventArgs e)
{
myClassObject.playSoundFromResource(sender, e);
}
allows you to create resource files (this is the .resx file, no?),
unlike the Express version, which does not.
I am trying to cut and paste code that MSDN recommends for playing a
simple wav file from inside an embedded file, like presumeably the
'resources' file .resx is. I want to embed the .wav file in a
'resource file' since I don't want the user storing the file on their
hard drive.
Using the Wizard, and clicking on various links, I was able to create
a resource file (.resx file?) that plays a small sound, 25 kb, that I
call "mywav.wav" (it plays this sound when you click on the icon for
the audio file in Visual Studio, in the .resx file and accompanying
files*). The .resx file only has this wav in it, nothing else, and
the .resx resource file is called "myaudio.resx".
I used the below code, which is pretty generic, but I cannot get
anything but a small 'ding' (which I think is the default Windows
error sound), but not the sound of "mywav.wav". I tried various
permutations of the string. Apparently this ADO.NET type language is
not strongly typed since it compiles with no problems, but it doesn't
run right...what is wrong?
RL
* I notice the .resx file is in XML format and contains a string for a
"PublicKeyToken". Perhaps, since I've never used this before, I need
to somehow log in for Visual Studio under my Administrator account (I
am using XP as the OS), and reset something?
//a class method declared and used inside of form Form 1, from an
object instantiated as "myClassObject"
public void playSoundFromResource(object sender, EventArgs e)
{
System.Reflection.Assembly a =
System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream s =
a.GetManifestResourceStream("<myaudio.resx>.mywav.wav"); //<--note
string--is this correct?
SoundPlayer player = new SoundPlayer(s);
player.Play();
}
// I use it on a button in Form form 1--when I click on a button, the
mywav.wav does not play, but a small 'ding' does...why?
private void button1_Click(object sender, EventArgs e)
{
myClassObject.playSoundFromResource(sender, e);
}