none
How can the MediaElement play WAV file that is part of a Resourcefile?

    Question

  • Hello,

    I have the medialelement playing wav files using thr URI, but now that I am about to release the application. I would like to make the wav files part of the exe assembly, but I can not find any examples of how to take the stream from the resource and make it a URI for the source of the mediaelement. Any help or sugestions would be greatly appreciated. Thank you.
    Thursday, April 02, 2009 6:47 AM

Answers

  • You can do something like this using SoundPlayer instead of MediaElement:

    private static void PlaySound(Uri uriResource)
    {
       using (SoundPlayer player = new SoundPlayer(Application.GetResourceStream(uriResource).Stream))
       {
          player.Play();
       }
    }

    In order to invoke the method:

    PlaySound(

    new Uri(@"pack://application:,,,/[Your Assembly Name];Component/Resources/Windows Ringout.wav"));

    new Uri(@"pack://application:,,,/[Your Assembly Name];Component/Resources/Windows Ringout.wav"));

     



    I am assuming that "Windows Ringout.wav" is in the folder Resource of the project and its build action is resource.

    • Marked as answer by Hua Chen Wednesday, April 08, 2009 5:52 AM
    Thursday, April 02, 2009 8:32 PM

All replies

  • You can do something like this using SoundPlayer instead of MediaElement:

    private static void PlaySound(Uri uriResource)
    {
       using (SoundPlayer player = new SoundPlayer(Application.GetResourceStream(uriResource).Stream))
       {
          player.Play();
       }
    }

    In order to invoke the method:

    PlaySound(

    new Uri(@"pack://application:,,,/[Your Assembly Name];Component/Resources/Windows Ringout.wav"));

    new Uri(@"pack://application:,,,/[Your Assembly Name];Component/Resources/Windows Ringout.wav"));

     



    I am assuming that "Windows Ringout.wav" is in the folder Resource of the project and its build action is resource.

    • Marked as answer by Hua Chen Wednesday, April 08, 2009 5:52 AM
    Thursday, April 02, 2009 8:32 PM
  • Hello Mariano,

    I did look into using the SoundPlayer, but it does not have a couple of events that the MediaElement provides. Thank you for the reply.
    Tuesday, April 14, 2009 8:59 PM