Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are keyboard shortcuts available ? #2859

Closed
Forium777 opened this issue Sep 20, 2020 · 2 comments
Closed

Are keyboard shortcuts available ? #2859

Forium777 opened this issue Sep 20, 2020 · 2 comments
Labels
status: archived Archived and locked; will not be updated type: question A question from the community

Comments

@Forium777
Copy link

Have you read the Tutorials?
Almost yes.

Have you read the FAQ and checked for duplicate open issues?
Yes.

What version of Shaka Player are you using?
Lastest release

Please ask your question
Hi,
I'm wondering if it is possible to use keyboard shortcuts by any way ? I tried to use well-known 'space' and 'F' shortcut to pause and fullscreen but player didn't react. Is it implemented ? If yes, how can I enable them ? If no, is it planned ?

Thanks!

@Forium777 Forium777 added the type: question A question from the community label Sep 20, 2020
@joeyparrish
Copy link
Member

For keyboard accessibility reasons, you can use tab to navigate to individual UI controls and manipulate them with the keyboard. For example, while the seek bar has focus, left and right arrows will seek. (Caveat: I just discovered that our focus indicator in the UI is broken. See #2863)

We don't have any global keyboard shortcuts, though, but you can easily add these to the window or document with your own app-level event listener. For example:

videoContainer = document.querySelector('.shaka-video-container');

document.addEventListener('keydown', (e) => {
  if (e.key == 'f') {
    videoContainer.requestFullscreen();
    e.preventDefault();
  } else if (e.key == ' ') {
    if (video.paused) {
      video.play();
    } else {
      video.pause();
    }
    e.preventDefault();
  }
});

We wouldn't do this by default, because a global listener would be a bad idea for applications with more than one instance of Shaka Player.

Does this help?

@Forium777
Copy link
Author

It does, thanks!

For people who want basics keyboard controls :

document.addEventListener('keydown', (e) => {
    const videoContainer = document.querySelector('video');
    let is_fullscreen = () => !!document.fullscreenElement
    let audio_vol = video.volume;
    if (e.key == 'f') {
        if (is_fullscreen()) {
            document.exitFullscreen();
        } else {
            videoContainer.requestFullscreen();
        }
        e.preventDefault();
    }
    else if (e.key == ' ') {
        if (video.paused) {
            video.play();
        } else {
            video.pause();
        }
        e.preventDefault();
    }
    else if (e.key == "ArrowUp") {
        e.preventDefault();
        if (audio_vol != 1) {
            try {
                video.volume = audio_vol + 0.05;
            }
            catch (err) {
                video.volume = 1;
            }
        }
    }
    else if (e.key == "ArrowDown") {
        e.preventDefault();
        if (audio_vol != 0) {
            try {
                video.volume = audio_vol - 0.05;
            }
            catch (err) {
                video.volume = 0;
            }
        }
    }
});
// Tested on Chrome 85 stable

@shaka-project shaka-project locked and limited conversation to collaborators Nov 21, 2020
@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Apr 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated type: question A question from the community
Projects
None yet
Development

No branches or pull requests

3 participants