Using javascript contolling the audio file when user works with new tab
in my application i have to control the audio file through keyboard keys when the page loads in browser which is done now i need to control the audio file with the same keys when i am working with new tab in browser that is if in my previous tab i have the audio file that is controlled through keyboard now when i open new tab i need to control the audio file that is in previous tab<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()
}
}
}
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>