MasterRacker
Active member
Playing a wav file has turned out to be fairly simple. The following code plays a file just fine if I feed it something like "C:\Test.wav"
My problem is that I don't want to haul sound files around with my app. I would prefer to add them to the project as embedded resources like I've done with some bitmaps.
According to the documentation, if I change the flag to SND_RESOURCE, I also need to set the hMod parameter to PlaySound to point to the resource. Unfortunately, I have been unable to find an example of how to do this. Has anyone out there done it this way?
Jeff
[purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me
Code:
public class Winmm
{
public enum SoundFlags : int
{
SND_SYNC = 0x0000, // play synchronously (default)
SND_ASYNC = 0x0001, // play asynchronously
SND_NODEFAULT = 0x0002, // silence (!default) if sound not found
SND_MEMORY = 0x0004, // Sound points to a memory file
SND_LOOP = 0x0008, // loop the sound until next PlaySound
SND_NOSTOP = 0x0010, // don't stop any currently playing sound
SND_NOWAIT = 0x00002000, // don't wait if the driver is busy
SND_ALIAS = 0x00010000, // name is a registry alias
SND_ALIAS_ID = 0x00110000, // alias is a predefined ID
SND_FILENAME = 0x00020000, // name is file name
SND_RESOURCE = 0x00040004 // name is resource name or atom
}
[DllImport("Winmm.dll")]
public static extern bool PlaySound(string Sound, IntPtr hMod, SoundFlags sFlags);
public Winmm()
{
}
public static void PlayWavResource(string wav)
{
if (!PlaySound(wav, IntPtr.Zero, SoundFlags.SND_ASYNC | SoundFlags.SND_FILENAME))
{
// handle error: unable to play sound
}
}
}
My problem is that I don't want to haul sound files around with my app. I would prefer to add them to the project as embedded resources like I've done with some bitmaps.
According to the documentation, if I change the flag to SND_RESOURCE, I also need to set the hMod parameter to PlaySound to point to the resource. Unfortunately, I have been unable to find an example of how to do this. Has anyone out there done it this way?
Jeff
[purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me