Add shortcuts for changing playbackRate

This commit is contained in:
Omar Roth 2019-03-17 12:17:53 -05:00
parent 956dc382ea
commit d85020079f
1 changed files with 25 additions and 3 deletions

View File

@ -79,9 +79,9 @@ var player = videojs("player", options, function() {
seekStep: 5, seekStep: 5,
enableModifiersForNumbers: false, enableModifiersForNumbers: false,
customKeys: { customKeys: {
// Toggle play with K Key
play: { play: {
key: function(e) { key: function(e) {
// Toggle play with K Key
return e.which === 75; return e.which === 75;
}, },
handler: function(player, options, e) { handler: function(player, options, e) {
@ -92,23 +92,45 @@ var player = videojs("player", options, function() {
} }
} }
}, },
// Go backward 5 seconds
backward: { backward: {
key: function(e) { key: function(e) {
// Go backward 5 seconds
return e.which === 74; return e.which === 74;
}, },
handler: function(player, options, e) { handler: function(player, options, e) {
player.currentTime(player.currentTime() - 5); player.currentTime(player.currentTime() - 5);
} }
}, },
// Go forward 5 seconds
forward: { forward: {
key: function(e) { key: function(e) {
// Go forward 5 seconds
return e.which === 76; return e.which === 76;
}, },
handler: function(player, options, e) { handler: function(player, options, e) {
player.currentTime(player.currentTime() + 5); player.currentTime(player.currentTime() + 5);
} }
},
// Increase speed
increase_speed: {
key: function(e) {
return e.which === 190;
},
handler: function(player, _, e) {
size = options.playbackRates.length;
index = options.playbackRates.indexOf(player.playbackRate());
player.playbackRate(options.playbackRates[(index + 1) % size]);
}
},
// Decrease speed
decrease_speed: {
key: function(e) {
return e.which === 188;
},
handler: function(player, _, e) {
size = options.playbackRates.length;
index = options.playbackRates.indexOf(player.playbackRate());
player.playbackRate(options.playbackRates[(size + index - 1) % size]);
}
} }
} }
}); });