Freigeben über


Easy automatic ASX generation

Easy automatic ASX generation

In my first post, I thought it would be helpful to show how to use classic ASP to dynamically create ASX files for any file.

An ASX file is essentially a shortcut or playlist file for Windows Media Player. Technically when you are embedding Windows Media Player in a web page you can point directly to the content URL in the URL parameter without using an ASX. However, if you are simply providing a link on the web page where someone can click and launch the stand-alone Windows Media Player you should use an ASX file. Usually you’re using the MMS:// moniker when pointing to content stored on a Windows Media Services server. IE doesn’t have a problem with this since it knows how to deal with the mms moniker. We aren’t so lucky with other browsers.

If you have a ton of video files that you want to play then that means you’d theoretically need to create a ton of ASX files, one ASX for each WMV. However you can create a simple ASP page on your IIS web site to point to any content on your WMS server.

Start by creating an ASP page. I’ll call mine generateasx.asp and I’ll save it on my web server. Here are the contents:

<% Response.ContentType="video/x-ms-asf" %><asx version = "3.0">
<entry>
<ref href = "mms://mediaserver.contoso.com/<% Response.Write(Request.QueryString("url")) %>"/>
</entry>
</asx>

Note that there should not be any white space (blank lines) at the beginning of this ASP file and that the <asx version = "3.0"> must be on the first line. This is because some versions of WMP are hard coded to read the ASX version information on the first line.

Next I’m going to edit my HTML page (mine is “videolist.htm”) to include a query string with the path and filename to the video on my WMS server:

<a href=”generateasx.asp?url=pinball.wmv”>Click here to watch the video</a>

Both my videolist.htm and generateasx.asp are in the same folder on my IIS server which happens to be just the c:\inetpub\wwwroot folder. You’ll notice that on the query after generateasx.asp is simply the filename pinball.wmv. This is appended in the second line of the ASP page so that the URL that gets put into the ASX file is mms://mediaserver.contoso.com/pinball.wmv. This URL will work with any browser now.

Comments

  • Anonymous
    May 18, 2009
    This example is a nice straight forward solution for a single file requested by the client, but what if I need to dynamically build an ASX file with serveral entries in PHP pulled from a database?

  • Anonymous
    May 18, 2009
    The comment has been removed