views:

1299

answers:

3

Hi all,

Am trying to play audio from resource using Dot.net CF, I added an audio file for the resource Property in my application, and am try to using below sample resource file reference code for..

SoundPlayer player = new SoundPlayer(Assembly.GetExecutingAssembly().
    GetManifestResourceStream("blessedwav.wav"));
player.Play();

But this code doesn't play wav sound, If anyone know How to play the resource audio file using CF 3.5, Please give me some suggestion regarding this.

Thanks for advance.

Regards, Vimal

A: 

Try this.

//I added the File as Audio Resource in my Project
SoundPlayer player = new SoundPlayer(Properties.Resources.recycle);
player.Play();

I didn't tried with .Net CF. But it is working for me in C#.

Anuraj
am try this code, but it's not working .Net CF, It's showing Error : The best overloaded method match for System.Media.SoundPlayer.SoundPlayer(string)' has some invalid arguments. anyway Thanks anuraj
Hmm, so I think .Net CF got only one overload which is using string as the argument. Then why don't you save the file to a Temp location and play it from there.
Anuraj
A: 

Hi

I got the solution .Below code is Working very will in .Net CF,

// Convert a byte array to a stream

Stream audioStream= new MemoryStream(Properties.Resources.full_song_wav);

player = new SoundPlayer(audioStream);

player.Play()

Regards, vimal..

Nice to hear you got the solution :)
Anuraj
A: 

Is there any way to play sound from resources using String variable with resource name?

luk
Yes, this is what the origianl question was asking. Use GetManifestResourceStream to extract it.
ctacke