PlayResourceSoundDemo.Form1.resources
(1)
Assembly.GetManifestResourceStream
(1)
GetManifestResourceStream
(1)
GetManifestResourceNames
(1)
GetManifestResourseStream
(1)
Resource
(1)
Strings
(1)
GetName
(1)
Play Embedded Sound Resource?
Asked By Joe Cool
12-Mar-10 05:52 PM
I found this link a few years ago:
http://msdn.microsoft.com/en-us/library/3w5b27z4.aspx
And when I first tried it, it worked fine. I now have a really simple
app for personal use in mind and I want to be able to play an embedded
sound resource, but this code no longer seems to work.
The Assembly.GetManifestResourceStream is returning a null value.
Any ideas?
TIA,
Yep... You definitely embedded it?
Mike Lovell replied to Joe Cool
12-Mar-10 06:07 PM
Yep... You definitely embedded it? By default this is NOT the case, you
need to make sure in Properties on the sound file, "Build Action" is
Is it in a folder or just in the 'root' of your project?
Remember it needs the full name including namespace, so if my sound file was
called 'music.wav' in a folder called 'sounds' and my namespace was
'GoTinker.MyProject'
GoTinker.MyProject.Sounds.music.wav
If you really cannot find it, do a:
GetManifestResourceNames()
A print each array item to screen, that will show you where it is hiding!
--
Mike
GoTinker, C# Blog
http://www.gotinker.com
ouThanks for your interest in my dilemma and your response.
Joe Cool replied to Mike Lovell
12-Mar-10 08:26 PM

ou
Thanks for your interest in my dilemma and your response. Here is how
I added the wav file as a resource.
I opened the project's properties window and selected the resources
tab. I clicked on the dropdown that had the value "Strings" and
selected Audio. I then clicked on Add Resource dropdown and selected
Add Existing File. I had made sure that the wav file I wanted to add
was in the root of the project's project folder. I selected that file
from the add file dialog. The wav file appeared as an icon in the
content part of the window. I can right click on the icon and click
play and the wav file plays fine. The access modifier dropdown is
Internal.
Does this help?
was
According to the link I provided, the says that you must specify the
resource in the format:
The angle brackets are required and AssemblyName is case sensitive.
Likw I also said, this used to work. I also made sure the wav file
name was also specfied in the same case as the actual filename I added
which is the same as the resource name label under the icon. In my
case, the assembly name is PlayResourceSoundDemo. I have single
stepped through the code and examined the value of
assembly.GetName().Name and is definitely PlayResourceSoundDemo.
I examined the value returned by this method in the debugger and two
items are listed:
{string[2]}
[0]: "PlayResourceSoundDemo.Properties.Resources.resources"
[1]: "PlayResourceSoundDemo.Form1.resources"
Okay, this time just right click on your project and add an existing file.
Mike Lovell replied to Joe Cool
12-Mar-10 09:05 PM
Okay, this time just right click on your project and add an existing file.
Select your wav files and add it to the project, then select the wav file
from the solution explorer. Set its "Build Action" to "Embedded Resource",
save the project.
Run it again after doing the above and your wav file should turn up. Then
use the name in your "GetManifestResourceStream" call
--
Mike
GoTinker, C# Blog
http://www.gotinker.com
.ce",henThanks a lot for your help.
Joe Cool replied to Mike Lovell
12-Mar-10 09:21 PM
.
ce",
hen
Thanks a lot for your help. I found that the angle brackets should not
delimit the assembly name in the GetManifestResourseStream method.
Otherwise, your suggestions worked.
.ce",henOut of curiosity, I wonder why the way I did it did not work.
Joe Cool replied to Mike Lovell
12-Mar-10 10:29 PM
.
ce",
hen
Out of curiosity, I wonder why the way I did it did not work. After
all, I did add the wav file as a resource.
Well you know what they say, all's well that ends well!
Mike Lovell replied to Joe Cool
13-Mar-10 01:28 PM
Well you know what they say, all's well that ends well!
--
Mike
GoTinker, C# Blog
http://www.gotinker.com