从 silverlight 对象外部播放 silverlight 播放器

发布于 2024-12-10 21:40:32 字数 1703 浏览 0 评论 0原文

我有一个使用 MediaElement 的简单 Silverlight 播放器。由于我无法控制的原因,他们希望能够基于 ASP.NET 代码实现所有播放/暂停/停止、音量控制等,而不是在 Silverlight 中构建。我将 Silverlight 嵌入到我的 aspx 中,如下所示:

<object id="SilverlightPlayer" data="data:application/x-silverlight," 
                                    type="application/x-silverlight-2" width="750" height="460" >
<param name="source" value="ClientBin/VideoPlayer.xap"/>  
<param name="EnableGPUAcceleration" value="true" />
<param name="OnResize" value="HandleResize" />
<param name="autoUpgrade" value="true" />
<param name="initParams" id="SLInitParameters" value='video=MyVideo.wmv' />                    
</object>

我想让用户单击 ASPX 中的“播放”按钮,它将告诉 Silverlight 播放器播放视频。 (对于所有其他按钮也是同样的事情)我一直无法找到如何在任何地方执行此操作,因为似乎每个人都将这些控件构建到他们的 Silverlight 中。

非常感谢任何帮助。

更新
我正在使用以下内容重新创建 silverlight:

function CreateSilverlight(hostElement, source, initParams) {
        var pluginId = hostElement.id + "PluginId";

        hostElement.innerHTML = Silverlight.createObject(source, null, pluginId,
            {
                width: '750',
                height: '460',
                background: 'black',
                isWindowless: true,
                alt: '<!--Silverlight not installed-->',
                data: 'data:application/x-silverlight,',
                type: 'application/x-silverlight-2',
                EnableGPUAcceleration: true,
                version: '4.0',
                autoUpgrade: true
            },
            { onError: null, onLoad: null, OnResize: HandleResize },
            initParams, hostElement.id);
}

所以我没有对该对象的引用。

I have a simple Silverlight player that uses the MediaElement. For reasons out of my control, they want to be able to have all the play/pause/stop, volume controls etc. based in the ASP.NET code and not be built in Silverlight. I embed the Silverlight in my aspx as follows:

<object id="SilverlightPlayer" data="data:application/x-silverlight," 
                                    type="application/x-silverlight-2" width="750" height="460" >
<param name="source" value="ClientBin/VideoPlayer.xap"/>  
<param name="EnableGPUAcceleration" value="true" />
<param name="OnResize" value="HandleResize" />
<param name="autoUpgrade" value="true" />
<param name="initParams" id="SLInitParameters" value='video=MyVideo.wmv' />                    
</object>

I want to have the user click a "Play" button in the ASPX and it will tell the Silverlight player to play the video. (Same kind of thing for all the other buttons) I have been unable to find out how to do this anywhere since everyone it seems builds these controls into their Silverlight.

Any help is greatly appreciated.

UPDATE:
I am using the following to recreate the silverlight:

function CreateSilverlight(hostElement, source, initParams) {
        var pluginId = hostElement.id + "PluginId";

        hostElement.innerHTML = Silverlight.createObject(source, null, pluginId,
            {
                width: '750',
                height: '460',
                background: 'black',
                isWindowless: true,
                alt: '<!--Silverlight not installed-->',
                data: 'data:application/x-silverlight,',
                type: 'application/x-silverlight-2',
                EnableGPUAcceleration: true,
                version: '4.0',
                autoUpgrade: true
            },
            { onError: null, onLoad: null, OnResize: HandleResize },
            initParams, hostElement.id);
}

So I don't have the reference to the object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我一直都在从未离去 2024-12-17 21:40:32

在出现媒体元素的 silverlight 页面的构造函数中,调用:

HtmlPage.RegisterScriptableObject("player", this)

然后,您可以像这样向页面添加方法:

[ScriptableMember]
public void Play()
{
    this.MediaElement.Play();
}

[ScriptableMember]
public void Pause()
{
    this.MediaElement.Pause();
}

[ScriptableMember]
public void Stop()
{
    this.MediaElement.Stop();
}

这些 [ScriptableMember] 属性非常重要。然后,从 javascript 中,您可以执行以下操作:

var slApp = document.getElementById("SilverlightPlayer");
slApp.player.Play();

这将调用公开的“Play”方法,该方法又告诉 MediaElement 进行 Play()

In the constructor of your silverlight page on which the media element appears, call:

HtmlPage.RegisterScriptableObject("player", this)

Then, you can add methods to your page like this:

[ScriptableMember]
public void Play()
{
    this.MediaElement.Play();
}

[ScriptableMember]
public void Pause()
{
    this.MediaElement.Pause();
}

[ScriptableMember]
public void Stop()
{
    this.MediaElement.Stop();
}

Those [ScriptableMember] attributes are important. Then, from javascript, you can do:

var slApp = document.getElementById("SilverlightPlayer");
slApp.player.Play();

That would call the exposed "Play" method, which in turn tells the MediaElement to Play().

一场春暖 2024-12-17 21:40:32

您可以通过 Javascript 通过 HtmlPage.Window.Invoke() 方法从 HTML 到 Silverlight 进行通信。 查看此链接

You can communicate from HTML to Silverlight via Javascript through the HtmlPage.Window.Invoke() method. Check out this link.

花期渐远 2024-12-17 21:40:32

我不需要重新加载 silverlight 控件来让它加载不同的视频。我只需要通过 JS 到 silverlight 桥将新媒体路径传递到 silverlight mediaElement.Source 。我还解决了加载传递到页面的视频的问题,方法是添加 SL 加载到屏幕上后调用 js 函数。

I didn't need to reload the silverlight control to get it to load a different video. I just needed to pass a new media path to the silverlight mediaElement.Source via the JS to silverlight bridge. I also solved my issue of loading a video passed to the page by adding to invoke a js function once the SL was loaded on the screen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文