0

我需要实现 VLC ActiveX 的所有 JavaScript 事件。

问题是所有事件都在触发,我不确定代码有什么问题。

视频结束时,我至少需要看到一些警报消息。

在这里>>> registerVLCEvent('MediaPlayerEndReached', handleEvents);

但是没有喜悦。

代码:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=9">
    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
    <meta http-equiv="pragma" content="no-cache" />
    <title></title>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">

        function getVLC(name) {
            if (window.document[name]) {
                return window.document[name];
            }
            if (navigator.appName.indexOf("Microsoft Internet") == -1) {
                if (document.embeds && document.embeds[name])
                    return document.embeds[name];
            }
            else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
            {
                return document.getElementById(name);
                //return getRawObject(name);
            }
        }


        function registerVLCEvent(event, handler) {
            var vlc = getVLC("vlc2");

            if (vlc) {
                if (vlc.attachEvent) {
                    // Microsoft
                    vlc.attachEvent(event, handler);
                }
                else if (vlc.addEventListener) {
                    // Mozilla: DOM level 2
                    vlc.addEventListener(event, handler, false);
                }
                else {
                    // DOM level 0
                    vlc["on" + event] = handler;
                }
            }
        }

        // stop listening to event
        function unregisterVLCEvent(event, handler) {
            var vlc = getVLC("vlc2");
            if (vlc) {
                if (vlc.detachEvent) {
                    // Microsoft
                    vlc.detachEvent(event, handler);
                }
                else if (vlc.removeEventListener) {
                    // Mozilla: DOM level 2
                    vlc.removeEventListener(event, handler, false);
                }
                else {
                    // DOM level 0
                    vlc["on" + event] = null;
                }
            }
        }

        // event callback function for testing
        function handleEvents(event) {
            if (!event)
                event = window.event; // IE
            if (event.target) {
                // Netscape based browser
                targ = event.target;
            } else if (event.srcElement) {
                // ActiveX
                targ = event.srcElement;
            } else {
                // No event object, just the value
                alert("Event value" + event);
                return;
            }

            if (targ.nodeType == 3) // defeat Safari bug
                targ = targ.parentNode;
            alert("Event " + event.type + " has fired from " + targ);
        }

        // handle mouse grab event from video filter
        function handleMouseGrab(event, X, Y) {
            if (!event)
                event = window.event; // IE
            alert("new position (" + X + "," + Y + ")");
        }

        $(document).ready(function () {
            // Register a bunch of callbacks.
            registerVLCEvent('MediaPlayerNothingSpecial', handleEvents);
            registerVLCEvent('MediaPlayerOpening', handleEvents);
            registerVLCEvent('MediaPlayerBuffering', handleEvents);
            registerVLCEvent('MediaPlayerPlaying', handleEvents);
            registerVLCEvent('MediaPlayerPaused', handleEvents);
            registerVLCEvent('MediaPlayerForward', handleEvents);
            registerVLCEvent('MediaPlayerBackward', handleEvents);
            registerVLCEvent('MediaPlayerEncounteredError', handleEvents);
            registerVLCEvent('MediaPlayerEndReached', handleEvents);
            registerVLCEvent('MediaPlayerTimeChanged', handleEvents);
            registerVLCEvent('MediaPlayerPositionChanged', handleEvents);
            registerVLCEvent('MediaPlayerSeekableChanged', handleEvents);
            registerVLCEvent('MediaPlayerPausableChanged', handleEvents);



        });




    </script>
</head>
<body>
    <object width="720" height="408" id='vlc2' events="True" codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab"
        classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921">
        <embed type="application/x-vlc-plugin" pluginspage="http://www.videolan.org" version="VideoLAN.VLCPlugin.2"
            width="720" height="408" id="vlc1" />
        <param name="src" value="http://content.bitsontherun.com/videos/bkaovAYt-52qL9xLP.mp4" />
        <param name="ShowDisplay" value="True" />
        <param name="AutoPlay" value="False" />
    </object>
</body>
</html>
4

1 回答 1

1

嗯......所以事件根本不起作用......

所以我认为最好的想法是在 C# 端(调用)或 HTML 端实现一些方法来获取vlc.input.state值。

这是一个 HTML 示例:

$(document).ready(function () {
            start_timer = setInterval(function () {
              var vlc = getVLC("vlc2");
               var s = vlc.input.state;
               // alert(s);
            },
        1000);
        });
于 2013-02-13T17:07:56.303 回答