Questions Tags Users Unanswered

calling javascript in ck editor to play audio file through keyboard even while working with ck editor

Question is open.
Be the first to answer this question. (1 voice) (2215 views)
Below is my JavaScript code to play html5 audio file through keyboard with corresponding keyboard keys that are used to play through keyboard. But these keys are working only when my cursor is in the audio file below.

I have CK Editor; if I am typing something in CK Editor and using these keys while typing they are not working again. It works through key board keys only when my cursor focus is in the audio file. How can I make this audio file to work with these keys even when I am typing something at CK Editor?

<script>
        var audio = $("audio")[0];
        $(document).keydown(function (e) {
            var unicode = e.charCode ? e.charCode : e.keyCode;
            console.log(unicode);
        // F7
        if (unicode == 39) {
            audio.currentTime += 2;
        // F8
        } else if (unicode == 37) {
            audio.currentTime -= 2;
        }
        //F9
        else if (unicode == 109) {
            audio.volume += 0.1
        }
        //F10
        else if (unicode == 110) {
            audio.volume -= 0.1
        }
        // spacebar
        else if (unicode == 32) {
            if (audio.paused) {
                audio.play();
            }
            else {
                audio.pause()
            }
        }
        window.addEventListener("keydown", function (e) {
            // space, page up, page down and arrow keys:
            if ([32, 33, 34, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
                e.preventDefault();
            }
        }, false);
        });
    </script> 


My requirement is even when I am working with CK Editor my keys should work to play, forward, backward, increase volume and decrease volume. But with this code I am able to control the audio file through these keys only when my cursor is at audio file. If I am out of it these keys are not working but they should work even when my cursor focus is out of audio file

  <CKEditor:CKEditorControl ID="CKEditor1" BasePath="~/ckeditor/" runat="server"></CKEditor:CKEditorControl>


This is my CK Editor where user types something while listening. If I am using these keys while typing at CK Editor keys are not working. How can I make these keys to work even when I am typing at ckeditor also?

Your Answer

Limit of files to attach: 3 / Max total size: 1024 KB
File:
Description:
remove