Click here to Skip to main content
13,087,902 members (77,608 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I have a project that I am working on and in this project is a resource file called resource1 which I created through the GUI. I added music into the resource1 file but I am not sure how to play the music from there.

I've looked up some tutorials on how it's done which they use something like in this forum.[^]

they use something like:

properties.Resources."the name of file"

For some reason when I get to the Resources. part I am unable to find the music file's name to finish the code.

I've also tried this:

 SoundPlayer player = new SoundPlayer();

Will appreciate all help,

Posted 7-Nov-12 0:39am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First thing is first... You don't set the player.SoundLocation property by calling the .Equal method. You would simply set it like player.SoundLocation = "location Uri"; The way you have that coded would return true or false whether the current sound location matched that string never actually setting the sound location.

However, you can't really do that because you embedded the sound in a resource file. You need to use the resource manager to load the resource from the .resx and then load it into the player. Something like this should do the trick:

ResourceManager manager = new ResourceManager("Resource1",typeof(App).Assembly);
 Stream mediaStream = manager.GetStream("Age_Of_Mythology_Soundtrack___Eat_Your_Potatoes");
 SoundPlayer player = new SoundPlayer();
 player.Stream = mediaStream;

Of course, the resource file has to be compiled as an embedded resource.

MR. AngelMendez 13-Nov-12 4:41am
Thanks, sorry for the long reply. How do I embed the resource file?
Jason Gleim 13-Nov-12 14:58pm
Add the file to the project and then open its properties. Change the file type to Embedded Resource.
MR. AngelMendez 15-Nov-12 19:25pm
thanks it works :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100