嵌入对象的时间更新事件监听器

Javascript - timeupdate event listener for Embed object

本文关键字:更新 事件 监听器 时间 对象      更新时间:2023-09-26

要连接搜索栏,我使用以下代码。我可以搜索视频但是搜索栏没有随着视频移动

    <embed pluginspage="http://www.videolan.org"
    type="application/x-vlc-plugin"
    width="640"
    height="480"
    toolbar="true"
    loop="false"
    text="Waiting for video"
    windowless="true"
    bgcolor="#000000"
    branding="true"
    allowfullscreen="true"
    src="./videos/mikethefrog.mp4"
    id="video"
    name="vlc" />
   <input type="range" id="seek-bar" value="0" onChange='seekBar();'>

JS

    window.onload = function() {
        var vlc = getVLC("vlc");
        // Update the seek bar as the video plays
        var video = document.getElementById("video");
        var seekBar = document.getElementById("seek-bar");
        var mediaLen = vlc.input.length;
        video.addEventListener("timeupdate", function() {
        // Calculate the slider value
        var value = (100 / mediaLen) * vlc.input.time;
        // Update the slider value
        seekBar.value = value;
        });
     function seekBar(){
    var vlc = getVLC("vlc");
    var seekBar = document.getElementById("seek-bar");
    var mediaLen = vlc.input.length;
    // Event listener for the seek bar
    seekBar.addEventListener("change", function() {
        // Calculate the new time
        var time = mediaLen * (seekBar.value / 100);
        // Update the video time
        vlc.input.time = time;
                //vlc.playlist.play();
                console.log(vlc.input.time);
    });

    // Pause the video when the seek handle is being dragged
    seekBar.addEventListener("mousedown", function() {
            console.log('pause');
                vlc.playlist.pause();
    });
    // Play the video when the seek handle is dropped
    seekBar.addEventListener("mouseup", function() {
            console.log('play');
        vlc.playlist.play();
    });
}
}

Error: Error calling method on NPObject! video.addEventListener("timeupdate", function() {

添加为全局变量:

var tracker;

删除这段代码:

video.addEventListener("timeupdate", function() {
        // Calculate the slider value
        var value = (100 / mediaLen) * vlc.input.time;
        // Update the slider value
        seekBar.value = value;
});

在此区域替换:

tracker= setInterval(track_audio, 100);

现在来跟踪音频:

function track_audio() {
    var vlc = getVLC("vlc");
    var seekBar = document.getElementById("seek-bar");
    var mediaLen = vlc.input.length;
    // Calculate the slider value
    var value = (100 / mediaLen) * vlc.input.time;
    // Update the slider value
    seekBar.value = value;
}