how to play embedded .wav sound resource in C# using SoundPlayer

Trying to create a simple app that plays a .wav file when you click a button...

target platform is windows mobile 6 CE 3.5 in C# using visual studio 2008 pro

in properties of solution, assembly name is listed as soundboard and default namespace is soundboard.

.wav file has been added as a resource, and set to embed in build options property for the resource

when compiling, and running on the windows mobile emuator, i get ZERO compilation errors, but when I click on the button all I get is a "system beep"

i am a total newb, can someone show me how to access the resource stream properly? i have a feel the path to the resource is not correct or im not looking it up properly....also I don't know how to use reflector

private void button1_Click(object sender, EventArgs e)
        {
            SoundPlayer sp = new SoundPlayer();
            sp.Stream =
            this.GetType().Assembly.GetManifestResourceStream("soundboard.Properties.Resources.moo1");
            sp.Play();
        }

Open in new window

romerorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
In WinForms, you could just do:

        private void button1_Click(object sender, EventArgs e)
        {
            SoundPlayer sp = new SoundPlayer();
            sp.Stream = Properties.Resources.moo1;
            sp.Play();
        }

Not sure if that will work in WinCE...
0
romerorAuthor Commented:
the error that returns is
Error      1      Cannot implicitly convert type 'byte[]' to 'System.IO.Stream'

on

            sp.Stream = Properties.Resources.moo1;
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Does it work this way?

            System.IO.MemoryStream ms = new System.IO.MemoryStream(Properties.Resources.moo1);
            SoundPlayer sp = new SoundPlayer();
            sp.Stream = ms;
            sp.Play();

(sorry...don't have WinCE)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

romerorAuthor Commented:
that compiled with zero issues, but crashed on the device emulator

error.jpg
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Try passing the MemoryStream directly to the SoundPlayer constructor:

            SoundPlayer sp = new SoundPlayer(new System.IO.MemoryStream(Properties.Resources.moo1));
            sp.Play();

(sorry...can't test it out myself)
0
romerorAuthor Commented:
same crash on the device emulator....

i do not mind testing this out at all..I am trying to learn to program and I have been researching this particular problem for a couple of days and seem to be doing everything right just can't get it to work :)

this wil be a good documentation for SoundPlayer :)
0
romerorAuthor Commented:
I just checked to make sure it wasn't something quirky with the smartphone emulator i'm debugging/deploying on so I hooked up my phone, same exact results...

0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
You could try using the PlaySound() API instead:
http://msdn.microsoft.com/en-us/library/ms229685(VS.80).aspx
0
romerorAuthor Commented:
wave file was corrupt or wrong type of file!

before using the file i checked to make sure device could play it as well as on pc

your solution worked as soon as I replaced the wav file with another one!
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Haha...glad you figured it out.  =)
0
romerorAuthor Commented:
I *knew* it had to be something simple, even tho I'm a noob

I was only trying to play a simple wav file and it is currently 2010 i figured it couldn't be more than 2 or 3 lines of code lol

your first and second solutions were spot on......

thanks again for the persistence in trying to help! :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.