Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, November 28, 2011

Programmatically use MediaWebPart Client object model Sharepoint 2010

The code below uses ECMAScript (JavaScript, JScript) object model to access the media player.

Here are the steps :

1. The first thing to consider is to add a reference to the below script file in your project.

2. Add a media player webpart on your page.

3. The ECMAScript for setting up the properties for the media player webpart are :

//Gets the media player.
function getMediaPlayer()
{
var p = document.getElementById(“MediaPlayerHost”)
var obj = p.getElementsByTagName(“object”);
return obj[0].Content.MediaPlayer;
}

//Initialize the media player object and set values for its properties. Customize MediaUrlField and PreviewURLField values for your local environment.
function init()
{
var serverStr = window.location.href;
serverStr = serverStr.substr(7);
serverStr = serverStr.substr(0, serverStr.indexOf(“/”));

document.getElementById(“MediaURLField”).value = “http://” + serverStr + “/documents/test.wmv”;
document.getElementById(“PreviewURLField”).value = “http://” + serverStr + “/documents/test.jpg”;
document.getElementById(“TitleField”).value = “API Test Page”;
document.getElementById(“TemplateURLField”).value = “http://” + serverStr + “/Style%20Library/XAML/AlternateMediaPlayer.xaml”;
}

//Set properties of the media player, including media URL, preview image URL, template URL, title, autoplay, whether to repeat, and default display mode.
function SetMediaSource()
{
var elm = document.getElementById(“MediaURLField”);
var p = getMediaPlayer();
p.MediaSource = elm.value;
}
function SetPreviewImageSource()
{
var elm = document.getElementById(“PreviewURLField”);
var p = getMediaPlayer();
p.PreviewImageSource = elm.value;
}
function SetMediaTitle()
{
var elm = document.getElementById(“TitleField”);
var p = getMediaPlayer();
p.MediaTitle = elm.value;
}
function SetTemplateSource()
{
var elm = document.getElementById(“TemplateURLField”);
var p = getMediaPlayer();
p.TemplateSource = elm.value;
}
function SetAutoPlay()
{
var elm = document.getElementById(“autoPlayCB”);
var p = getMediaPlayer();
p.AutoPlay = elm.checked;
}
function SetLoop()
{
var elm = document.getElementById(“loopCB”);
var p = getMediaPlayer();
p.Loop = elm.checked;
}
function SetDisplayMode()
{
var elm = document.getElementById(“DisplayModeSelect”);
var p = getMediaPlayer();
p.DisplayMode = elm.value;
}

No comments:

Post a Comment