要连接Seek Bar,我正在使用以下代码。我能够寻找视频,但是随着视频向前移动,搜索栏不会移动
HTML
<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() {
答案 0 :(得分:0)
将其添加为全局:
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;
}