locked
How to play sound from resources?

    Question

  • I can play MySound.wav from my disk, using

    SoundPlayer media=new SoundPlayer(@"c:\MySound.wav");

    media.Play();

    But i want this sound was included to my program. I add it to resources. but

     SoundPlayer media=new SoundPlayer( CsApp.Properties.Resources.MySound);

    media.Play();

    doesn't work...

    Saturday, February 11, 2006 8:35 PM

Answers

  • I added tada.wav (X:\Windows\Media\tada.wav) to resources.
    This code I added to Form_Load event:

    Stream str = Properties.Resources.tada;
    SoundPlayer snd = new SoundPlayer(str);
    snd.Play();
    Saturday, February 11, 2006 9:48 PM

All replies

  • I added tada.wav (X:\Windows\Media\tada.wav) to resources.
    This code I added to Form_Load event:

    Stream str = Properties.Resources.tada;
    SoundPlayer snd = new SoundPlayer(str);
    snd.Play();
    Saturday, February 11, 2006 9:48 PM
  • When i run my program there is a error: "Wav header is corruped"...
    Sunday, February 12, 2006 10:53 AM
  • If the wav header is corrupted then the file that you want to play isn't PCM wav file.
    (PCM uses an uncompressed and lossless storage method. However, wav files can also be used to store compressed formats such as MP3. The headers in the file differentiate the content type because the wav file extension is still used.)
    Sunday, February 12, 2006 11:47 AM
  • Thanks!!! It was a wrong wav (not Microsoft) format )))
    Sunday, February 12, 2006 1:41 PM
  • How i can syncronize it now? I put


    Stream str = Properties.Resources.tada;
    SoundPlayer snd = new SoundPlayer(str);
    snd.Play();

    this.close;


    to Click_ExitButton Event. But Form closing before the sound play to the end. How to do that sound was played to the end and only than form closing?

    Sunday, February 12, 2006 2:00 PM
  • Instead of :
        snd.Play()
    you need to use:
        snd.PlaySync();
    Sunday, February 12, 2006 4:46 PM
  • Thanks
    Sunday, February 12, 2006 4:56 PM
  • Can u plz help me in this program..........i wan sme help frm u
    Wednesday, October 28, 2009 10:22 AM