我有一个带有Expression Player的silverlight控件,其中公开了一个特定的方法,可以在javascript中使用:
[ScriptableMember]
public void PlayMedia(string mediaFileUri)
{
PlaylistItem playListItem = new PlaylistItem();
playListItem.MediaSource = new Uri(mediaFileUri);
myPlayer.Playlist.Items.Add(playListItem);
myPlayer.Playlist.AutoPlay = true;
}
。 然后我想在我的asp.net应用程序中嵌入这个silverlight控件。我是这样做的:
<div id="silverlightControlHost">
<object id="silverlightPlayer" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/SilverlightPlayer.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50826.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
此外,我有一个javascript方法,以动态加载媒体文件:
<script type="text/javascript">
function PlayMedia(mediaFileUri) {
var silverlightPlayer = document.getElementById("silverlightPlayer");
if (silverlightPlayer == null) {
alert("Silverlight player not loaded");
}
else {
alert("Silverlight player loaded");
silverlightPlayer.content.SilverlightPlayer.PlayMedia(mediaFileUri);
}
}
</script>
然后当我以这种方式执行这个js方法时:
<body onload="PlayMedia('http://mediadl.microsoft.com/mediadl/IISNET/media/BigBuckBunny_1080p24.wmv');">
一切正常。
但是我想将参数传递给托管silverlight控件的Default.aspx页面,然后计算url并将其传递给silverlight控件。链接可以如下:http://localhost/Default.aspx?id=21487982
我做的是:我在Page_Load方法中创建了一个适当的代码来执行js脚本,但是我收到消息:“加载Silverlight播放器”但后来我收到一个错误:“无效的指针“在线:
silverlightPlayer.content.SilverlightPlayer.PlayMedia(mediaFileUri);
我的Page_Load方法如下所示:
protected void Page_Load(object sender, EventArgs e)
{
var id = Page.Request.QueryString["id"];
string url = ComputeUrl(id);
string script = "<SCRIPT LANGUAGE='JavaScript'> ";
script += "PlayMedia('"+url+"')";
script += "</SCRIPT>";
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"ClientScript", script);
}
有人可以告诉我在这种情况下该怎么办?
答案 0 :(得分:0)
您在寻找InitParams吗? 将参数直接传递给silverlight。这可能对你有帮助。 http://msdn.microsoft.com/en-us/library/cc838255%28v=vs.95%29.aspx
http://msdn.microsoft.com/en-us/library/cc189004%28v=vs.95%29.aspx