我決定實現我自己的解決方案,目前似乎工作得很好。我想我會分享它,以防其他人遇到這樣的問題。
請原諒實施。這只是一個概念證明:
必要的JavaScript:
//Handles the key down event (so the user can hold a key down to continue)
$(document).keydown(function (e) {
//Rewind
if (e.keyCode == 37 && (!rewinding)) {
rewinding = true;
//Pause the player
$("#player").jPlayer("pause");
RewindTrack();
rwaction = window.setInterval(function() { RewindTrack() }, 500);
}
else if (e.keyCode == 39 && (!fastforward)) {
fastforward = true;
//Pause the player
$("#player").jPlayer("pause");
FastforwardTrack();
ffaction = window.setInterval(function() { FastforwardTrack() }, 500);
}
});
//Ends the action
$(document).keyup(function (e) {
//Rewind
if (e.keyCode == 37) {
rewinding = false;
window.clearInterval(rwaction);
$("#player").jPlayer("pause");
}
else if (e.keyCode == 39) {
fastforward = false;
window.clearInterval(ffaction);
$("#player").jPlayer("pause");
}
});
//Related function
function GetPlayerProgress() {
return ($('.jp-play-bar').width()/$('.jp-seek-bar').width() * 100);
}
//Handles rewinding
function RewindTrack() {
//Get current progress and decrement
var currentProgress = GetPlayerProgress();
//Rewinds 10% of track length
var futureProgress = currentProgress - 10;
//If it goes past the starting point - stop rewinding and pause
if (futureProgress <= 0) {
rewinding = false;
window.clearInterval(rwaction);
$("#player").jPlayer("pause", 0);
}
//Continue rewinding
else {
$("#player").jPlayer("playHead", parseInt(futureProgress, 10));
}
}
//Fast forwards the track
function FastforwardTrack() {
//Get current progress and increment
var currentProgress = GetPlayerProgress();
//Fast forwards 10%
var futureProgress = currentProgress + 10;
//If the percentage exceeds the max - stop fast forwarding at the end.
if (futureProgress >= 100) {
fastforward = false;
window.clearInterval(ffaction);
$("#player").jPlayer("playHead", parseInt($('.jp-duration').text().replace(':', '')));
}
else {
$("#player").jPlayer("playHead", parseInt(futureProgress, 10));
}
}
Working Demo
$(使用左爲快退,右爲快進箭頭)( 「#播放器」) .jPlayer(「pause」,0); 這不適用於ipad/iphone。你能幫我嗎? – jit 2012-09-05 05:19:14