Rob Garrett - Blogs

Welcome to Rob Garrett - Blogs Sign in | Join | Help
in Search
Google

Software/Technology Discussion

Software and Technology Tid-bits

Embedding Windows Media and Quicktime into ASP.NET pages

I know there are numerous web sites and blogs about this subject.  Since I had to write some code for "Fred" to render on-line video, and embedding video in web pages can be somewhat fiddly to get right, I figured I'd blog the C# code for my future reference.  If hosting on-line video in your web site interests you, be sure to check out Sahil Malik's post on the subject.

Below are two examples, which create the HTML for embedding Windows Media and Quicktime sources.  To use this code, compile either or both examples into your ASP.NET project (or into a referenced class library assembly), bung a PlaceHolder on your page and during the load event of your page pass the instance of your PlaceHolder control to the desired method.  The location should either be a relative URL or absolute URL to the hosted video file, which can be a streaming location or an HTTP location.

Embedding Windows Media:



Embedding Quicktime:




That's it.... now if you're really good, you can detect the client operating system, by looking for the word "Windows" in the user agent string (hint:Request.UserAgent) and calling the correct method above.

I tested the above code using FireFox and IE (Windows and Mac).  Windows Media will play in FireFox if you have the Windows Media Plugin (Windows version ships with latest version of Windows Media Player) installed, and the rendering Quicktime requires the plugin from Apple (duh).
Share this post: Email it! | bookmark it! | digg it! | reddit!
Published Saturday, February 25, 2006 10:31 AM by Rob Garrett

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Sahil Malik said:

Y'know we shudda called the project Margaret. That way we could say,

Margaret is such a bitch!!! Margaret has been throwing tantrums lately. Margaret has been keeping me awake for long hours. Sorry darling I'll be late from work - Margaret needs me.

.. and so on.
February 25, 2006 11:35 AM
 

Rob Garrett said:

Yeah, but "we gave Margaret a good kicking today" would not go over well.
February 25, 2006 2:26 PM
 

John said:

Hello!! Thanks !! wow!! realy cool!!!
March 9, 2007 3:38 AM
 

LeeH said:

Sweeeeeeet! Thanks alot!
March 16, 2007 10:01 AM
 

Sergei Shelukhin said:

Umm.... uiMode mini doesn't work for embed in FF 2.0 or Opera, any way to fix it?
May 9, 2007 6:07 AM
 

Rob Garrett said:

Sergei,

   Since writing this code I implemented a version using control adapters (unfortunately I cannot post it because it's copyrighted by my employer), you might want to try that route with the code above to implement control versions to target different platforms.

R.

May 9, 2007 9:20 AM
 

Sergei Shelukhin said:

The problem is not with the wrapper, it is with the object itself, I have done a lot of googling and embed doesn't seem to have uiMode attribute.
May 12, 2007 6:24 PM
 

Lee said:

Hi Rob In your sample code, what is the object called bo, and where does it get initialized? "The name 'bo' does not exist in the current context" Thanks Lee.
September 22, 2007 1:54 PM
 

Rob Garrett said:

Lee,

  Oops, BO is a business object I used in the application in which I pulled this code.  Ignore it in the context of this example and pass a string for the mime-type.

R.

September 23, 2007 10:29 PM
 

Ken Maz said:

Wow! This is exactly what I needed. Thanks!
November 15, 2007 3:36 PM
 

Daz said:

Thanks Rob - luvooo xx
March 18, 2008 3:04 PM
 

PETER said:

Thanks Rob but I'd like to ask how could you modify the code so that the windows media player could display visualization?
April 3, 2008 11:52 AM
 

Usman said:

nice ... How i can pre-activate media player or quick time player in internet explorer since IE requires a user to click on it?
May 12, 2008 9:13 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit

Blurb


Head Shot
Rob Garrett is a British Expat living in Maryland USA. Rob is a trained software engineer and experienced in Windows .NET development.

Rob enjoys listening to Rock music, posting to blogs, driving in the country with the sunroof open, beer (not in conjunction with country driving) and spending time with his family.

This Blog

Syndication

Powered by Community Server, by Telligent Systems