Jump to content

how to pass audio id to multiple tabs in the same browser


Recommended Posts

<script type="text/javascript">
     document.onkeydown = function () {
         sysend.broadcast();
     };
     var audio1 = document.getElementById("player");
     window.addEventListener("keydown", playPauseKb, false);

     alert(audio1.id);
     //document.getElementById("audio1").onkeypress = function () {
     document.getElementById("audio1.id").onkeydown = function playPauseKb(event) {
             var x = event.keyCode;
             console.log(x);
             if (x == 113) {
                 audio.currentTime -= 5;//F9 Rewined
             }

             else if (x == 114) {
                 //event.data.$.preventDefault();
                 audio.currentTime += 5;//F11 forword                
             }

             else if (x == 115) {
                 if (audio.paused) {
                     audio.play();//F10 paly/pause
                 }
                 else {
                     audio.pause()
                 }
             }
       
         sysend.broadcast();
     };

    </script>

here I am getting id as alert but instead of displaying the id as alert I need to pass the id to multiple tabs and these multiple tabs are opened by the user dynamically to this dynamically opened mutiple tabs I need to pass the id in such a way that my extension works with keydown And when I am in that tab where I have audio this is my code

 

<asp:TemplateField HeaderText="Play Audio File" ItemStyle-Width="200px" ItemStyle-HorizontalAlign="Center" > 
            <ItemTemplate>
                  <audio controls="controls" id="player">
                     <source src='<%# Eval("audio") %>' />
                     your browser does not support the audio element.</audio>
            </ItemTemplate>
       </asp:TemplateField>

<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()
                 }
             }

         }
    </script>

which works with keydown but if user opens a new tab dynamically keydown is not working how can I control the audio with keydown from multiple tabs

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...