从Embedded Player捕获SendPlayStateChangeEvents

时间:2014-03-09 18:41:26

标签: javascript vb.net media-player

我使用以下脚本嵌入媒体播放器:

<script type="text/javascript">
        document.write('<OBJECT id="Player"');
        document.write(' classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"');
        document.write(' width=210 height=60>');
        document.write(' <PARAM name="Volume" value="100">');
        document.write(' <PARAM NAME="SendPlayStateChangeEvents" VALUE="True">');
        document.write(' <PARAM name="uiMode" value="full"></OBJECT>');
</script>

我正在尝试捕获“SendPlayStateChangeEvents”,例如,当我停止播放器时:

<script type="text/javascript">
    function getPlayState(){
        var getit = document.getElementById("Player");
        getit.settings.volume = 100;
        alert(getit.PlayState); 
    }
</script>

“getPlayState()函数不起作用......

如何使用JavaScript监控PlayState?

(我正在使用vs web dev 2010,windows 7,vb.net)

1 个答案:

答案 0 :(得分:0)

我终于弄清楚了......

嵌入是正确的:

  <script type="text/javascript">
        document.write('<OBJECT id="Player"');
        document.write(' classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"');
        document.write(' width=210 height=60>');
        document.write(' <PARAM name="Volume" value="100">');
        document.write(' <PARAM NAME="SendPlayStateChangeEvents" VALUE="1">');
        document.write(' <PARAM name="uiMode" value="full"></OBJECT>');
    </script>

为了监视SendPlayStateChangeEvents,您需要使用setInterval(function()在脚本中设置一个计时器。

   <script type="text/javascript">
       function showPlayer() {
           $('a.play').on("click", function (event) {
               var t = event.clientY;
               var l = event.clientX + 200;
               $(Player).css("position", "fixed").css("top", t + "px").css("left", l + "px");
               $(Player).show();
               myVar = setInterval(function () { getPlayerStatus() }, 2000);
           })
       }
    </script>

然后计时器将每两秒检查一次事件变化。在这种情况下,它会检查&#34;停止&#39;或&#34;准备好&#34;,然后暂停计时器。

<script type="text/javascript">
    function getPlayerStatus() {
        var s = Player.PlayState;
        if (s == 1 || s == 10) {
            $(Player).hide();
            setTimeout(myStopFunction(), 500);
        };
    }
    function myStopFunction() {
        clearInterval(myVar);
    }
</script>

希望这些信息对某人有帮助....