Friday, November 12, 2010

Code: Silverlight Media Element Relative Urls

The best way I’ve found to use relative urls for media items in Silverlight is to place the media files (mp3, wmv, mp4, etc) in the ClientBin folder of the website (same directly as the .xap file) 


Ensure that the Build Action is set to Content and Copy To Ouput Directory is set to Copy if Newer:


Then you can reference the files with a single forward slash then the file name:

<MediaElement x:Name="DangerZoneTune" Source="/DangerZoneTune.mp3"></MediaElement>