How to control the audio from new tab that is opened in the browser by the user
Below is my code which controls the audio through keyboard keys after the page loads now what i need is i need to control the audio from the new tab opened in the browser that means the user opens this new tab in the browser i don't need any javascript to open the new tab but i need to control the audio from that newly opened tab using keyboard keys 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()
}
}
}
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()
}
}
});
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>