none
playing sound stored as a project resource

    Question

  • My project contains a number of Audio resources that were created from .wav files. I want to play those sounds in the application. I found code samples as follows:

    SoundPlayer s = new SoundPlayer(@"mypath.mysoundfile.wav");

    s.play();

    However I would rather use the Audio resources that are stored as resources. The IDE shows variables representing these resources such as

    Resource1.resourceName

    How can I play this Audio resource?

    Help!

    Saturday, April 08, 2017 5:26 PM

Answers

  • Hi friend,

    You could try this code:

    using System.Media;
    .
    .
    .
    .
    
    Stream str = Properties.Resources.YourWaveSoundFile;
    SoundPlayer player = new SoundPlayer(str);
    player.Play();

    Hope it helps.

    Best regards,

    Fletch


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, April 10, 2017 2:34 AM

All replies