好的,所以我有一個事件監聽器在監聽「timeupdate」事件的視頻播放器上,每秒發生5到10次,每次當前時間碼爲視頻播放器已更新。我正在編寫一個函數,允許我根據視頻的播放位置在特定時間內執行某些操作。 IE - 在320幀暫停視頻,在420幀暫停視頻。由監聽器調用的Javascript函數將不會更新全局變量
爲了節省處理能力,我創建了一個名爲notStarted的全局變量,它基本上告訴函數是否啓動事件(暫停視頻)或停止事件(取消暫停視頻),以便當notStarted爲true時,我們開始事件,當notStarted爲false時,我們結束事件。
這是函數。它在開始事件後成功地使notStarted成爲假,但之後它不會將其改回爲真。
更新:這裏是所有相關的代碼
var frameRate = 30;
var players=new Array(_V_("video_canvas_1"), _V_("video_canvas_2"));
var canv1 = players[0];
var canv2 = players[1];
var canv1Play = 1; // Autoplay is enabled, so we set the Play state to 1 off the bat.
var canv2Play = 1; // Autoplay is enabled, so we set the Play state to 1 off the bat.
var conchShell = _V_("conch"); // Lord of the Flies, Bitch!
var token = 0;
function currentFrame(e) {
return frameRate * e.currentTime();
console.log('currentTime * frameRate:' + frameRate * e.currentTime());
}
// Accepts player objects as arguments - canv1, canv2
function pause(){
for (var i = 0, j = arguments.length; i < j; i++){
arguments[i].pause();
console.log(arguments[i] + '1 is paused'); /* TODO: REMOVE CONSOLE LOGS BEFORE DEPLOYMENT */
}
}
function play(){
for (var i = 0, j = arguments.length; i < j; i++){
arguments[i].play();
console.log(arguments[i] + '1 is playing');
}
}
function syncSingleToConch(e) {
e.currentTime(conchShell.currentTime());
}
function syncToConchShell() {
async.parallel([
async.each(players, syncSingleToConch, function(err){ console.log('error with the each function'); }),
conchShell.currentTime(arguments[0].currentTime()),
async.each(players, playSingle, function(err){ console.log('error with the each function'); })
]);
}
function pauseAtKeyFrame(startStop, player, frameStart, frameEnd) {
if (startStop === "start") {
pause(player);
console.log('pausing player');
}
if (startStop === "stop") {
play(conchShell, canv1, canv2);
setTimeout(syncToConchShell(canv1), 3500);
startStop = "start";
console.log('playing player');
}
}
var currentEvent = 0;
var notStarted = true;
var frameEvents = [
{
"type": pauseShowModal,
"frameStart": 200,
"frameEnd": 220,
"canvas": canv1
},
{
"type": pauseAtKeyFrame,
"frameStart": 320,
"frameEnd": 420,
"canvas": canv1
},
{
"type": showDivAtTime,
"frameStart": 111,
"frameEnd": 311,
"canvas": canv1,
"div": "frame100"
}
];
function keyFrames() {
if (notStarted === true && frameEvents[currentEvent].frameStart < currentFrame(conchShell) && frameEvents[currentEvent].frameEnd > currentFrame(conchShell)) {
frameEvents[currentEvent].type("start", frameEvents[currentEvent].canvas, frameEvents[currentEvent].div);
notStarted = false;
console.log(notStarted);
} else if (notStarted === false && frameEvents[currentEvent].frameEnd < currentFrame(conchShell)) {
console.log(notStarted);
frameEvents[currentEvent].type("stop", frameEvents[currentEvent].canvas, frameEvents[currentEvent].div);
currentEvent++;
notStarted = true;
}
}
conchShell.addEvent("timeupdate", keyFrames);
你可以請更新代碼,看看你在哪裏調用ketFrames()? – ricardohdz 2013-04-22 14:17:25
您是在$(document).ready還是window.onload中聲明變量?我知道這很愚蠢,但它曾經發生過一次,我沒有注意到它們並沒有在全球範圍內宣佈。更新了 – multimediaxp 2013-04-22 14:22:48
以顯示事件偵聽器和所有正在調用的函數keyFrame。 conchShell是一個我不惹惱的視頻播放器。我用它爲頁面上的所有其他玩家設置基準時間碼。 – coulbourne 2013-04-22 14:29:25