mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Only bind media keys for TV and browsers not having mediaSession
This commit is contained in:
parent
bdce41c3ae
commit
68bac17a46
1 changed files with 38 additions and 0 deletions
|
@ -45,6 +45,11 @@ const KeyNames = {
|
|||
*/
|
||||
const NavigationKeys = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'];
|
||||
|
||||
/**
|
||||
* Keys used for media playback control.
|
||||
*/
|
||||
const MediaKeys = ['MediaRewind', 'MediaStop', 'MediaPlay', 'MediaFastForward', 'MediaTrackPrevious', 'MediaTrackNext', 'MediaPlayPause'];
|
||||
|
||||
/**
|
||||
* Elements for which navigation should be constrained.
|
||||
*/
|
||||
|
@ -89,6 +94,16 @@ export function isNavigationKey(key) {
|
|||
return NavigationKeys.indexOf(key) != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns _true_ if key is used for media playback control.
|
||||
*
|
||||
* @param {string} key - Key name.
|
||||
* @return {boolean} _true_ if key is used for media playback control.
|
||||
*/
|
||||
export function isMediaKey(key) {
|
||||
return MediaKeys.indexOf(key) != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns _true_ if the element is interactive.
|
||||
*
|
||||
|
@ -116,6 +131,11 @@ export function enable() {
|
|||
return;
|
||||
}
|
||||
|
||||
// Ignore Media Keys for non-TV platform having MediaSession API
|
||||
if (!layoutManager.tv && isMediaKey(key) && 'mediaSession' in navigator) {
|
||||
return;
|
||||
}
|
||||
|
||||
let capture = true;
|
||||
|
||||
switch (key) {
|
||||
|
@ -167,6 +187,24 @@ export function enable() {
|
|||
case 'Pause':
|
||||
inputManager.handleCommand('pause');
|
||||
break;
|
||||
case 'MediaPlayPause':
|
||||
inputManager.handleCommand('playpause');
|
||||
break;
|
||||
case 'MediaRewind':
|
||||
inputManager.handleCommand('rewind');
|
||||
break;
|
||||
case 'MediaFastForward':
|
||||
inputManager.handleCommand('fastforward');
|
||||
break;
|
||||
case 'MediaStop':
|
||||
inputManager.handleCommand('stop');
|
||||
break;
|
||||
case 'MediaTrackPrevious':
|
||||
inputManager.handleCommand('previoustrack');
|
||||
break;
|
||||
case 'MediaTrackNext':
|
||||
inputManager.handleCommand('nexttrack');
|
||||
break;
|
||||
|
||||
default:
|
||||
capture = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue