Locating your MediaElement Video Source File in a Silverlight 3 Control

In this Demo I will show 3 ways to have your web page locate your MediaElement’s video file.

I have created a Silverlight 3 application and let it automatically create a web site to host the control.

clip_image002

 

Drag a <MediaElement> onto the UserControl and set its source file attribute.

clip_image004

 

Drag the video file using window explorer and drop it in the root of my Silverlight’s UserControl project.

clip_image006

 

Note the size of this file is about 25mb.

clip_image008

 

I will demo 3 different methods for setting the location so that the web page can find it.

 

Method 1

Highlight the video and set its “Build Action” to “Content”

Your properties will look like below:

clip_image010

 

Change the source attribute to have a forward slash before the video name.

clip_image012

 

Build the solution.

Test using the test aspx page (TestMediaTestPage.aspx) in your web project and the video should work fine.

Check the size of your xap in the ClientBin folder. Notice that it includes the video file.

clip_image014

 

Method 2

Again from a fresh Silverlight solution containing the 2 projects, drag the video to the root of the Silverlight project.

Highlight the video and set its “Build Action” to “Resource”.

 

Add a <MediaElement> onto the UserControl and set its source file attribute.

In this case a slash is not used in front of the file name in the MediaElement

clip_image016

 

Build the solution.

Once again check the size of your xap in the ClientBin folder. Notice that it includes the video file.

Test using the test aspx page (TestMediaTestPage.aspx) in your web project and the video should work fine.

 

Method 3

Again from a fresh Silverlight solution containing the 2 projects, drag the video to the root of the Silverlight project.

 

Highlight the video and verify its “Build Action” is set to “None”.

 

Add a <MediaElement> onto the UserControl and set its source file attribute.

It does not matter if a slash is in front of the file name or not in the MediaElement

 

Build the solution and using windows explorer check the size of the xap file in the ClientBin.

Notice that it does not include the video file.

 

clip_image018

 

Using windows explorer, drag the video file into the ClientBin folder.

clip_image020

 

Test using the test aspx page (TestMediaTestPage.aspx) in your web project and the video should work fine.

Here is a video recap.

«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345