This post describes how to build an object tag for Windows Media Player that will work on multiple browsers. Recently while writing some code for Windows Media Player, I took a walk down Google lane and came across an article on A List Apart by Elizabeth Castro describing how to code video player Object tags without resorting to the non-standards compliant embed tag. Starting with the code in the article and then tweaking some parameters to generate 1 set of output for Internet Explorer and 1 set for “everyone else”, I was able to generate an object tag that worked in the following browsers: Internet Explorer 7, Firefox 3.0.10, Opera 9.64, Safari 4.0, Google Chrome 2.0 and Flock 2.5 (all running on Windows XP, sorry – I am too poor to buy a Mac). This MSDN article describing how Windows Media Player PARAM tags work in Firefox and Internet Explorer was also helpful, and would be useful reference if you use this code as the basis for more complex coding.

Click here to see the Live Example

Here’s the code, it’s just a page and code-behind based on the conditional display of Panels to render the Object tag depending on the browser type (i.e. if it’s Internet Explorer or not).

WindowsMediaPlayerExample.aspx

<%@ Page Language="C#" AutoEventWireup="true" 
    CodeFile="WindowsMediaPlayerExample.aspx.cs" 
    Inherits="WindowsMediaPlayerExample" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Mike Knowles - Windows Media Player Multiple Browser Example</title>    
<style type="text/css">        
    body {
        background-color:#EFEFEF;
        color:#01010F;
        font-family:Verdana, "lucida grande", sans-serif;
        font-size:1em;
        padding-left:54px;
        line-height:1.4em;
    }        
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="width:540px; padding-top:18px;">
<p>This example demonstrates how to build a Windows Media 
Player object tag that plays on multiple browsers.</p>
<p>For more detail, refer to the <a href="">blog post on this topic</a>.</p>

<asp:Panel ID="InternetExplorerPanel" Visible="false" runat="server">
<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" 
    type="application/x-ms-wmp" width="500" height="330">
  <param name="url" 
    value="http://silverlight.services.live.com/60107/HD%20Future%20Markers/video.wmv" />      
  <param name="autoStart" value="true" />
  <p>You must install 
  <a href="http://www.microsoft.com/windows/windowsmedia/player/download/" 
    target="_blank">Windows Media Player</a> to view this content.</p>
</object>        
</asp:Panel>
<asp:Panel ID="DefaultPanel" Visible="false" runat="server">
<object type="application/x-ms-wmp" width="500" height="330"
    data="http://silverlight.services.live.com/60107/HD%20Future%20Markers/video.wmv">
  <param name="src" 
    value="http://silverlight.services.live.com/60107/HD%20Future%20Markers/video.wmv" />    
  <param name="autoStart" value="true" /> 
  <p>You must install <a href="http://www.microsoft.com/windows/windowsmedia/player/download/"
    target="_blank">Windows Media Player</a> to view this content.</p>
</object>
</asp:Panel>    
</div>
</form>
</body>
</html>

WindowsMediaPlayerExample.aspx.cs

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WindowsMediaPlayerExample : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.UserAgent.Contains("MSIE"))
        {
            this.InternetExplorerPanel.Visible = true;
            this.DefaultPanel.Visible = false;
        }
        else
        {
            this.DefaultPanel.Visible = true;
            this.InternetExplorerPanel.Visible = false;
        }
    }
}
Bookmark and Share  Comments [4] | Permalink | ASP.NET
Tuesday, February 16, 2010 1:27:36 AM (Mountain Standard Time, UTC-07:00)
Hi, I tried this page in Chrome (latest version) and FF (latest version). Seems not to work. Only IE works. Did you try it?
Peter
Tuesday, February 16, 2010 10:29:56 PM (Mountain Standard Time, UTC-07:00)
Thanks for letting me know it wasn't working. Please try it now. I think what happened was the video I was linking to is no longer available and that was causing it not to display anything. I uploaded a short video to the web site and it's playing for me now in Chrome and Firefox on Windows 7 and XP. I also added a link to the Firefox/Chrome plugin download page that will be displayed when the media player is not found. Let me know if that doesn't fix it.
Monday, March 15, 2010 3:51:45 AM (Mountain Standard Time, UTC-07:00)
Hi, I tried your code but it could not work on FF.

I have the following 2 problems in viewing.
1) Could not view on Firefox.
2) Could not view image on avi files, there is only sounds.

For your info, I am running video files from my c drive. E.g C:\iTube\fssf.wmv
Thuggiec
Wednesday, May 26, 2010 12:47:52 AM (Mountain Daylight Time, UTC-06:00)
Hi ! the code is not working in Opera v 9.22.The WMP is showing but no video is playing nor is it asking to download any necessary plugin.
gomesh munda

Leave a Comment

Name (required)
Email (will not be published)
Website
 

Comment Preview
Subscribe
Top 5 Posts
Add Google Analytics to a SharePoint Publishing Site
Integrating jQuery 1.3, ASP.NET 3.5 Visual Studio 2008
Add Custom Table Formats to SharePoint Content Editor
Configuring log4net for SharePoint Windows Authentication
Convert Visual Studio 2008 Class Library Project to Web Application Project
Tags
ASP.NET (5) dasBlog (5) GoogleAnalytics (2) jQuery (1) log4net (2) SharePoint (18) WebDesign (3)
 
 
 
Spreadfirefox Affiliate Button
 
Download Notepad++