views:

112

answers:

2

I am having issues with setting the Silverlight 4 MediaElement Source property in my ASP.NET MVC 2 application. I have a Windows 7 development machine and a Windows Server 2008 staging server.

Locally I have been using a MediaElement source like:

<MediaElement x:Name="VideoMediaElement" Source="Assets/126.mp4">
...
</MediaElement>

This source works on my development machine and my staging server, but I found that this was only working in Google Chrome. After a great deal of research and testing I converted my app to set the source to be:

<MediaElement x:Name="VideoMediaElement" Source="http://localhost:40000/ClientBin/Assets/126.mp4"&gt;
...
</MediaElement>

Using this type of Uri allows my video to play on my local server in Internet Explorer as well as Google Chrome. When I push this up to my staging server the path is calculated to be:

<MediaElement x:Name="VideoMediaElement" Source="http://myDomain/MyVirtualDir/ClientBin/Assets/126.mp4"&gt;
...
</MediaElement>

This looks fine to me, but the video will not play in any browser on the staging server.

The differences I see between my development environment and the staging server is the virtual directory. Are there known problems or tricks when setting a full Uri that includes a virtual directory?

What is the preferred method for loading a video file from a file structure into a Silverlight 4 MediaElement?

A: 

Did check fiddler what the actual http request/response tells you? Maybe there are security infos (cross-domain access) or at least you get more details what's going on under the cover... you can find fiddler right here: http://www.fiddler2.com/fiddler2/

server info
I have been using fiddler. It shows 404 errors on "/MyVirtualDir/ClientBin/Assets/126.mp4" but I'm not sure that tells me much. I know it can't find it, which is why I am pretty sure it is a pathing problem. If I use the relative path like "Assets/126.mp4" fiddler does not show a problem; but again, that only seems to work in Google Chrome.
Steve Hook
did you set the build action to resource for the video then the xap is large but you can access it relative.
server info
+1  A: 

My first steps in diagnosing this would be:-

  • stop using chrome. Make it all work in IE then test other browsers.
  • stop using the full URL. Given that the XAP, the host page and the resource are all on the same server we know we shouldn't need it so lets not use it.
  • Don't use a browser running on the staging server, use another Client machine to test with.
  • Install Fiddler2 on the client machine as server info suggests and see what is actually being requested.

Have you tried "/assets/126.mp4" instead of "assets/126.mp4" ?

If you are getting a 404 from a URL that looks good check the server mime map, is there a mapping for .mp4?

Also check file access security.

AnthonyWJones
Thanks for your help. You answered my question of if I need the full path or not. So to be clear, I do not need the full path in my source if it is all living under the same ClientBin.Further more, a MIME type for ".mp4" with a type of "video/mpeg" was missing from my server. Once I added this, both relative and absolute paths started working again. Now only if it would stream it and not download the whole file first then play it, but that will be a topic for another question.
Steve Hook
@Steve: Some research on "Silverlight Progressive Download" might help your download issue.
AnthonyWJones