JG Vimalan's Blog

It is all about coding!

Media Player webpart

The following code snippet gives an idea of creating media player webpart,

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls; 

//This is a custom webpart which render media files

namespace MyMediaPlayer
{
    public class MediaPlayer:WebPart
    {
        public MediaPlayer()
        {
           
        } 

 //Add more properties to get the media files path etc
 //in my case, i hard coded the media file path
    

       protected override void Render(HtmlTextWriter output)
        {
            output.Write(“<div align = \”center\””);
            output.Write(“OBJECT id = \”” + base.WebPartManager.UniqueID +
                “\” CLASSID = \”CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\” type=\”application/x=oleobject\”>”);
            output.Write(“<PARAM NAME = \”FileName\” VALUE =\”” + “http://mysite/General%20Documents/sampleVideo.wmv” + “\”>”);
            output.Write(“<PARAM NAME = \”z-index\” VALUE =\”-1\”>”);
            output.Write(“<PARAM NAME = \”AutoRewind\” VALUE =\”True\”>”);
            output.Write(“<PARAM NAME = \”SendOpenStateChangeEvents\” VALUE =\”True\”>”);
            output.Write(“<PARAM NAME = \”TransparentAtStart\” VALUE =\”True\”>”);
            output.Write(“<PARAM NAME = \”TransparentOnStop\” VALUE =\”True\”>”);
            output.Write(“<embed type = \”application/x-mplayer2\””);
            output.Write(“<pluginspage = \”http://www.microsoft.com/windows/Download/Contents/Products/MediaPlayer/\“”);
            output.Write(“filename=\”http://mysite/General%20Documents/sampleVideo.wmv\“”);
            output.Write(“showcontrols=\”True\””);
            output.Write(“showdisplay=\”True\””);
            output.Write(“windowlessvideo=\”1\””);
            output.Write(“align=\”middle\”>”);
            output.Write(“</embed>”);
            output.Write(“</OBJECT>”);
            output.Write(“</div>”);
        }
    }

Deploy this webpart. You will get output as,

MyMediaPlayer

You can have more control over your media player by setting auto play, height, width etc,  

Regards,

JG Vimalan

Advertisements

September 20, 2009 - Posted by | SharePoint

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: