You must Sign In to post a response.
  • Category: JavaScript

    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>
  • #767616
    Hi,
    In New Tab, try to find your player. Once you get that, you can perform all the operations on it.

    <script type="text/javascript">
    function GetPlayer() {
    var control = window.location.search.substring(1).split('=')[1];
    alert(control);
    }
    </script>

  • #767621
    how to find the player in new tab what i need is i have audio file and ck editor in one tab when i run the web application there i can control the audio from ckeditor using keyboard keys but now what i need is if user is working in other tab then he should be able to control the audio from that tab using F10 key on keyboard

  • #767623
    i had added the same code to my above posted code but it is not working can anybody please help me out as i am new to this


  • Sign In to post your comments