我的代码无法在Chrome上运行,但在Firefox上运行正常。它不应该按照预期重绕30秒,而只是暂停Chrome上的播放器。知道我设置错了吗?
以下是我一直在使用的代码:
function jumpBySeconds(s) {
try{playerInstance.seek(playerInstance.getPosition()+s);}catch(e){}
}
function displayButtons() {
var playButton = document.getElementsByClassName('jw-controls jw-reset')[0];
playButton.style.display = "block";
}
function hideButtons() {
var playButton = document.getElementsByClassName('jw-controls jw-reset')[0];
playButton.style.display = "none";
}
function addControlbarListeners(){
var timer;
var player = document.getElementsByClassName('jwplayer')[0];
player.onmouseover = function(){displayButtons();};
player.onmouseout = function(){hideButtons();};
player.addEventListener("mousemove",function(){
displayButtons();
clearTimeout(timer);
timer=setTimeout(mouseStopped,2000);
});
function mouseStopped(){
hideButtons();
}
}
function addPlayForwardAndBackwardButtons(){
var playBack = document.createElement("img");
playBack.id = "-30sb";
playBack.setAttribute('class','jw-icon jw-icon-display jw-button-color jumpBackward jw-reset');
playBack.onclick = function(){
jumpBySeconds(-30);
}
var middleBar = document.getElementsByClassName('jw-display-icon-container jw-reset')[0];
middleBar.appendChild(playBack);
middleBar.setAttribute('style',"background-color:rgba(0, 0, 0, 0.0); border: 0px; display: flex;");
var playButton = middleBar.childNodes[1];
middleBar.removeChild(playButton);
middleBar.appendChild(playButton);
var playForward = document.createElement("img");
playForward.id = "+30sb";
playForward.setAttribute('class','jw-icon jw-button-color jw-icon-display jw-reset jumpForward');
playForward.onclick = function(){
jumpBySeconds(30);
}
var middleBar = document.getElementsByClassName('jw-display-icon-container jw-reset')[0];
middleBar.appendChild(playForward);
// set icon to center
middleBar.style.width = "100%";
middleBar.style.margin = "-1.0em auto 0";
}
playerInstance.onPause(function(){
console.log("video stopped");
});
playerInstance.onPlay(function(){
console.log("video playing...");
});
playerInstance.onReady(function(){
addPlayForwardAndBackwardButtons();
addControlbarListeners();
});