4

I have embedded a windows media player in a web page, using the usual <object> and <embed> tags. The video is served by an ashx (http handler). When I try to play the video, I usually (but not always) get an error message telling me that the file extension (ashx) does not match the file format.

This happens in IE (9 & 10) and also in Firefox (latest) with the WMP plugin.

I know that the tags (with classid, etc) are correct because the media player displays and allows me to click the 'play' button.

The ashx returns the correct mime type (video/x-ms-wmv) and a valid file name (somevideo.wmv) in the response headers. I have tried content-disposition attachment and inline.

I have tried urls using 'http://', 'https://', and '//' (which I prefer)

If I put the url (including the .ashx) of the video file in the browser address bar directly, the video downloads and plays.

If I modify the object tag to use a direct path to the video file (/somewhere/somevideo.wmv), it works - but I can't use this as a solution.

The same ashx serves up video and audio in various other formats with out any fuss - it just seems that the embedded windows media player doesn't like it.

This has been working for several years - I think this is some new behavior, though I can't identify what has changed, other than browser updates.

EDIT: a more careful study in Fiddler showed something I missed before. If I access the video directly (by entering my ashx url in the browser address bar), the video plays in the standalone media player. The content type and disposition headers are correct.

However, when using the embedded player, I usually (not always) get OPTIONS and PROPFIND requests from user agent "Microsoft-WebDAV-MiniRedir/6.1.7601". I do not have WebDAV enabled, and I do not respond to options and propfind requests. The embedded player does not request the actual video file.

Correction - I do actually respond to the options request - here is the request and response info from fiddler :

OPTIONS http://mydomain.com/myhandler.ashx HTTP/1.1
User-Agent: Microsoft-WebDAV-MiniRedir/6.1.7601
translate: f
Connection: Keep-Alive
Host: mydomain.com

HTTP/1.1 200 OK
Allow: OPTIONS, TRACE, GET, HEAD, POST
Server: Microsoft-IIS/7.5
Public: OPTIONS, TRACE, GET, HEAD, POST
X-Powered-By: ASP.NET
Date: Tue, 24 Dec 2013 16:03:49 GMT
Content-Length: 0

This is followed by four identical requests, using PROPFIND instead of OPTIONS. the response is 404.

Ray
  • 21,485
  • 5
  • 48
  • 64

2 Answers2

2

To successfully play the file you need to specify Content-Disposition and Content-Type headers correctly.

In your ashx, make sure you add following lines,

 Response.AddHeader("Content-Disposition","attachment;filename='a.wmv'");
 Response.AddHeader("Content-Type","video/wmv");

Please identify correct name and content-type based on type of file you have, and substitute them in above code.

Looks like it has Cross Origin Resource Sharing Issue,

make sure you are returning correct headers for different domain as suggested by following response.

 Access-Control-Allow-Origin: *
 Access-Control-Allow-Methods: GET, POST, OPTIONS
 Access-Control-Allow-Headers: X-Requested-With, Accept, Content-Type, Origin
 Access-Control-Max-Age: 1728000

Replace * with domain where your page is hosted which embeds your media player.

Akash Kava
  • 39,066
  • 20
  • 121
  • 167
  • I am doing this already. I use "video/x-ms-wmv" as the mime type. I tried "video/wmv" as you suggested, but it didn't make any difference. – Ray Dec 24 '13 at 14:46
  • I think "Content-Type" will be enough, because "Content-Disposition: attachment" is usually used for displaying a "Save As ..." dialog and storing a linked content locally. – KoViMa Dec 24 '13 at 14:47
  • @Ray, then the error is somewhere else, try putting Try Catch around whole Execute Request method and log it. – Akash Kava Dec 24 '13 at 14:59
  • There are no exception being thrown. See my edit - the ashx is performing correctly, but the embedded player is not actually requesting the file – Ray Dec 24 '13 at 15:07
  • If you don't respond to OPTIONS request correctly, it will probably abort the request. I had similar problem, in OPTIONS request, some exception was thrown, and player would not make second request and everything would halt. Your ASHX may work correctly, however your server should respond correct headers for OPTIONS. – Akash Kava Dec 24 '13 at 15:40
  • Then the question is, what response is the media player looking for? The response my IIS sends to the options request is 'Allow: OPTIONS, TRACE, GET, HEAD, POST'. And then there are the propfind requests. – Ray Dec 24 '13 at 16:06
  • If you post your fiddler trace, I can suggest by looking at it, currently what does IIS respond? Typically it should respond successful response along with x-allow etc headers. – Akash Kava Dec 24 '13 at 16:20
  • added the options response to the question – Ray Dec 24 '13 at 16:23
  • What are request headers? – Akash Kava Dec 24 '13 at 16:25
  • sorry - added the full info – Ray Dec 24 '13 at 16:30
  • Your options response looks ok, what is next request? – Akash Kava Dec 24 '13 at 16:35
  • the next request is PROPFIND - it is exactly the same as the options request (except for the verb...) – Ray Dec 24 '13 at 18:09
  • I just noticed that you edited your answer with another idea. I tried the additional headers, but no change. I don't think it is a security issue. This works with dozens of other file types, including videos (mp4, flv). It is only in media player that I have a problem. – Ray Dec 24 '13 at 19:41
0

Have you tried appending the file type to the end of the URL? for example:

http://www.mywebsite.com/MyVideoHandler.ashx?videofile=123245&.wmv

This example assumes that the file is of wmv type.

Craig Moore
  • 1,093
  • 1
  • 6
  • 15