.NET Framework - 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,
PlayResourceSoundDemo.Form1.resources
(1)
Assembly.GetManifestResourceStream
(1)
GetManifestResourceStream
(1)
GetManifestResourceNames
(1)
GetManifestResourseStream
(1)
Resource
(1)
Strings
(1)
GetName
(1)
Mike Lovell replied to Joe Cool
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
Joe Cool replied to Mike Lovell

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"
Mike Lovell replied to Joe Cool
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
Joe Cool replied to Mike Lovell
.
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.
Joe Cool replied to Mike Lovell
.
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.
Mike Lovell replied to Joe Cool
Well you know what they say, all's well that ends well!
--
Mike
GoTinker, C# Blog
http://www.gotinker.com
data to excel in ASP.net 3.5? Thanks, Chandan ASP.NET Web Controls Discussions GetManifestResourceStream (1) XmlDataDocument (1) Assembly.GetManifestResourceStream (1) Excel (1) StreamReader (1) StreamWriter (1) StringWriter (1) UploadFile (1) I have some code XmlDataDocument xmlDataDoc = new XmlDataDocument(ds); XslTransform xt = new XslTransform(); StreamReader reader = new StreamReader(typeof (WorkbookEngine).Assembly.GetManifestResourceStream(typeof (WorkbookEngine), XmlTextReader xRdr = new XmlTextReader(reader); xt.Load(xRdr, null, null); StringWriter sw = new
Here is the code: ContextMenuStrip cm = new ContextMenuStrip(); Image image; Stream s; s = this.GetType().Assembly.GetManifestResourceStream ("myProjectName.resourcepicturename"); image = Image.FromStream(s); cm.Items.Add(new ToolStripMenuItem("Menu Item Text", image Error is: Value of 'null' is not valid for 'stream'. Any help appreciated. C# Discussions GetManifestResourceStream (1) Assembly.GetManifestResourceStream (1) Image.FromStream (1) ToolStripMenuItem (1) FromStream (1) Stream (1) Are you sure you have
Xmlpath = new System.Xml.XPath.XPathDocument(filename); XslTransform xsl = new XslTransform(); Stream xmlStream = this.GetType().Assembly.GetManifestResourceStream ("SolutionNameSpaceName.FormatConvertion.xslt"); System.Xml.XmlReader xmlReader = new System.Xml.XmlTextReader(xmlStrea m ); xsl.Load xsl.Transform(Xmlpath, list, textWriter); My problem is with this statement: Stream xmlStream = this.GetType().Assembly.GetManifestResourceStream ("SolutionNameSpaceName.FormatConvertion.xslt"); I have given my Application nameSpace "." Xslt filename but it returns null System.Xml.XPath.XPathDocument (1) System.Xml.XmlTextReader (1) System.Xml.XmlReader (1) UTF8Encoding (1) GetManifestResourceStream (1) XPathDocument (1) Assembly.GetManifestResourceStream (1) Xslt (1) Rasheed, Ensure that your Namespace.FomatConvertion.xslt is all cased correctly and embedded resource as follows string script = string.Empty; using (StreamReader reader = new StreamReader(this.GetType().Assembly.GetManifestResourceStream("DataManager.Script.xml"))) { script = reader.ReadToEnd(); } If you add in the Resource using the