Unable to fast forward and slow the audio playing using javascript
When i run my aspx page in the web page i will get an audio which can be controlled using keyboard keys F10 key is used to play and pause the audio,F11 is used forward the audio by 5 sec,F9 is used to backward the audi by 5 sec,F7 is used to fast forward the audio and F8 is used to slow the audio that means when i use F7 and F8 the audio should increase its speed than the normal speed and when i use F8 the audio should become slow than the original speed.Below the audio i have ck editor where i should be able to control the audio with all the above mentioned functionalities.Everything works that is F10,F11 and F9 are working but F7 and F8 are not working that is fast forwarding and backwarding are not working how can i do this.
<script type = "text/javascript">
var audio = document.getElementById("player");
window.addEventListener("keydown", playPauseKb, false);
function playPauseKb(event) {
var x = event.keyCode;
console.log(x);
if (x == 120) {
audio.currentTime -= 5;//F9 Rewined
}
else if (x == 122) {
//event.data.$.preventDefault();
audio.currentTime += 5;//F11 forword
}
else if (x == 121) {
if (audio.paused) {
audio.play();//F10 paly/pause
}
else {
audio.pause()
}
}
else if (x == 118)
{
Slow();
event.data.$.preventDefault();
}
else if (x == 119)
{
Forward();
event.data.$.preventDefault();
}
}
var count = 0;
function Forward() {
event.data.$.preventDefault();
count++;
if (count == 1) {
audio.playbackRate = 1.2;
}
if (count == 2) {
audio.playbackRate = 1.4;
}
if (count == 3) {
audio.playbackRate = 1.0;
count = 1;
}
}
var count = 0;
function Slow() {
event.data.$.preventDefault();
count++;
if (count == 1) {
audio.playbackRate = 0.9;
}
if (count == 2) {
audio.playbackRate = 0.8;
}
if (count == 3) {
audio.playbackRate = 1.0;
count = 1;
}
}
window.addEventListener("keydown", function (e) {
// f6, page up, page down and arrow keys:
if ([117, 119, 120, 121, 122, 123, 113, 33, 34, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
e.preventDefault();
}
}, false);
</script>
<script type = "text/javascript">
$(document).ready(function () {
CKEDITOR.on('instanceCreated', function (e) {
e.editor.on('contentDom', function () {
e.editor.document.on('keydown', function (event) {
if (event.data.$.keyCode == 120) {
event.data.$.preventDefault();
audio.currentTime -= 5;//f10_Rewind
}
else if (event.data.$.keyCode == 122) {
event.data.$.preventDefault();
audio.currentTime += 5;//F11 farward
}
else if (event.data.$.keyCode == 121) {
event.data.$.preventDefault();
if (audio.paused) {
audio.play();//f6_play and pause
}
else {
audio.pause()
}
}
else if (event.data.$.keyCode == 118) {
event.data.$.preventDefault();
Slow();
}
else if (event.data.$.keyCode == 119) {
event.data.$.preventDefault();
Forward();
}
});
var count = 0;
function Forward() {
count++;
if (count == 1) {
audio.playbackRate = 1.2;
}
if (count == 2) {
audio.playbackRate = 1.8;
}
if (count == 3) {
audio.playbackRate = 1.0;
count = 1;
}
}
var count = 0;
function Slow() {
count++;
if (count == 1) {
audio.playbackRate = 0.9;
}
if (count == 2) {
audio.playbackRate = 0.8;
}
if (count == 3) {
audio.playbackRate = 1.0;
count = 1;
}
}
});
});
});
</script>