SoundPlayer

  • Thread starter Thread starter ORC
  • Start date Start date
O

ORC

I ran into this problem in my very simple C# code, which is the only code I
have added to the standard windows generated form ( the code is located in a
buttons click event):

Stream stream =
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
"Infbeg.wav");

The function always returns <undefined value> even though i have selected
"Infbeg.wav" as an embedded Ressource.

Thanks,
Ole
 
Typically you need to include the Namespace inside the string, so you should try:

Stream stream =
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
"Namespace.Infbeg.wav");

*****************************************
* A copy of the whole thread can be found at:
* http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-compact-framework/9053
*
* Report spam or abuse by clicking the following URL:
* http://www.dotnetmonster.com/Uwe/Abuse.aspx?aid=a83f35424e0d4cbca72b1fe6af1d4c81
*****************************************
 
Thanks Jordan,

It works! Funny thing is that on the full framework the first thing also
worked and with image files there weren't any problem either. But your
soultion works everytime -great!

Thanks
Ole
 
Hmmm...
Problem: What if the soundplayer is placed in another class than the main
class!? I can't get it to work!

In my main class i got this code in a button clik event:
SoundPlayer.Play ("MainClassNamespace.Infbeg.wav");

And in SoundPlayer.Play(string SoundName):
Stream stream =
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
SoundName);

I have tried all possible variations of SoundName like:
MainClassNamespace.SoundPlayerNamespace.Infbeg.wav
MainClassNamespace.SoundPlayerNamespace.SoundPlayer.Infbeg.wav
SoundPlayerNamespace.Infbeg.wav
SoundPlayerNamespace.SoundPlayer.Infbeg.wav

Hope someone will be able to help -

Thanks
Ole
 
The OpenNETCF SoundPlayer only works currently with wavs in files, not
embedded resources, so the string passed to SoundPlayer.Play must be a valid
file path.

Peter
 
Hi,

I'm not using the soundplayer from opennet but I'm making a simple version
of the coming SoundPlayer in CF2.0. I've got it to work in one compilation
just a minute ago - it seems that GetManifestResourceStream can't handle
spaces in the Solution name even thought that the NameSpace is renamed to
Solution_name as the main NameSpace in other words: if I make the a solution
without spaces it seems to work but I'll let you know when I'm finished.

Thanks
Ole
 
You can also use GetManifestResourceNames to get a collection of all the
embedded resource names in an assembly.

Peter
 
No I didn't know that - interresting! Thanks for the advice which I
certainly will use later.

I have now done further investigations concerning the use of spaces
/underscores in the project name/namespace .
The following call replaces the underscores in the name space with spaces:
"System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString()
"
And therefore causes the
"GetManifestResourceStream" to fail if they are located in another class .

Ole
 
Back
Top