0

I want to play the media element (not that it's matter I'm asking a global question here). I have a resource file for the media element which I wanna play but it's source demand a URI for example

mediaElement1.Source = new Uri(@"c:\users\SabrinaVazIsFuckingGod\video\22.wav");

now i dont have 22.wav as a path but in my "resource"

My File

I found out from my searching that some programmers are talking about packs but I dont know how to use them, so please if you know how, and can explain me or even better to give me example code I'll be grateful.

Thanks for the people who already answered, but they didnt answered my question, I want to have my media file in the exe and not in any other place.

Tiago
  • 2,156
  • 2
  • 18
  • 27
Superzarzar
  • 509
  • 2
  • 8
  • 16
  • 4
    Sabrina Vaz is one lucky gal. – Jay Riggs Jul 13 '13 at 07:23
  • The link you gave states it all, so what is the problem? did you change the property of the .wav file to resource? just change the URI to `new URI(@"/Resources/22.wav")` – Eyal H Jul 13 '13 at 07:25
  • no sorry it is not working i got an erorr while running if using your code http://s12.postimg.org/5fo1390bh/Sabrina_178.jpg – Superzarzar Jul 13 '13 at 07:42
  • Finally, someone with on SO with a sense of humor and is not completely dead on the inside and isn't a complete jerk to everyone. – Milo Jul 13 '13 at 08:58

3 Answers3

1

After some trial and error, I was able to get the following to work:

MyMediaElement.LoadedBehavior = MediaState.Play;
MyMediaElement.Source = new Uri(@"Resources\AudioFile.mp3", UriKind.Relative);

If you go to the properties of your media file in Visual Studio and set the Build Action to Content, and Copy to Output Directory to Copy if newer, that should do the trick. I tried playing around with the pack syntax you mentioned, but if these media files are going to be copied on build to a sub-folder alongside your executable, a simple relative path should do the trick.

Mark Carpenter
  • 17,445
  • 22
  • 96
  • 149
1

Make sure to Build Action to set as Resource and use following code

uri = new Uri(@"pack://application:,,,/Resources/22.wav", UriKind.RelativeOrAbsolute);
Chitta
  • 206
  • 2
  • 6
0

I don't know packages yet but the document you linked indicates that you should have the pack:// prefix, then an authority (which would be application:/// as your file is in your resources, but with the /// replaced by ,,, as the note explains) so that your URI would be of the form:

new URI(@"pack://application:,,,/Resources/22.wav")

Try that and see if it works.

Julien Rousseau
  • 975
  • 1
  • 9
  • 15