Problem in using OpenNetCF soundplayer class

please help me. i want to play a .wav file added to my solution's resources (file name is "start.wav"). i used the following code--

private void button1_Click(object sender, EventArgs e)
{
System.IO.Stream mystream = Properties.Resources.start;
OpenNETCF.Media.SoundPlayer myplayer = new OpenNETCF.Media.SoundPlayer();
myplayer.Stream = mystream;
myplayer.Play();
}

but error messase i get is "Cannot implicitly convert type 'byte[]' to 'System.IO.Stream".
is there any method to play a resource sound file.

please help




Answer this question

Problem in using OpenNetCF soundplayer class

  • Brett A. Scudder

    i am still facing some problems. let us ignore tht. all i want to know is that what is the easiest method to play a .wav file in the current directory in an embedded device application i.e. by using .net compact framework , as it does not support System.Media.Soundplayer Class.


  • joan_h

    I can guess that "start" variable is a byte array, and you are trying to assign a byte array to Stream object. You need to initialize a stream from that byte array buffer.

    Replace the first line in the event handler with this:

    MemoryStream mystream = new MemoryStream( Properties.Resources.start );

    First ask from http://www.opennetcf.org/forums/, if you have problems with the OpenNETCF.

  • Joe Jackson

    This is a sound advice

  • SideshowBob

    You could check out this post: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=280521&SiteID=1

    But if you use OpenNETCF, you can simpy use this code to play a sound file in your current application folder:

    SoundPlayer sound = new SoundPlayer("mySoundfile.wav");
    sound.Play();

    So simple is that.

  • Problem in using OpenNetCF soundplayer class