通过编程方式使用SharePoint 2010中的MediaWebPart客户端对象模型

下面的代码使用ECMAScript(Javascript,JScript)对象模型来访问媒体播放器。

以下是具体步骤:

1、第一件要考虑的事是在你的项目里添加一个引用到下面的脚本文件。

2、在页面中添加一个媒体播放器WebPart。

3、通过ECMAScript设置该媒体播放器WebPart的属性:

//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;
}

参考资料

Programmatically use MediaWebPart Client object model Sharepoint 2010

posted @ 2010-08-30 08:48  Sunmoonfire  阅读(476)  评论(0编辑  收藏  举报