0

I need to play a sound byte (MP3 or wav) from within a WPF application. I would like to use the MediaPlayer. I have a .wav file with; "Build Action" = Content and "Copy to Output Directory" = "Copy if Newer" and this file is located in the Resources directory of my app.

However, I just cant get the URI string right. (and maybe the Build Action is not correct)

CBreeze
  • 2,925
  • 4
  • 38
  • 93
Intensivist
  • 767
  • 2
  • 7
  • 19
  • Can you show us the `URI` string you have currently written? – CBreeze Feb 08 '16 at 14:39
  • This is the one (of many I tried) that isn't working: Uri u = new Uri("file://Resources/SoundByte.wav"); I also have to make sure that I have the Build Action correct – Intensivist Feb 08 '16 at 14:56

1 Answers1

0

I found this from Tolga Evcimen and it does work:

how to get relative path

var outPutDirectory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); var SoundBytePath = System.IO.Path.Combine(outPutDirectory, "Resources\SoundByte.wav");

Community
  • 1
  • 1
Intensivist
  • 767
  • 2
  • 7
  • 19