mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-05-13 01:51:28 +00:00
feat: player add media key support
This commit is contained in:
parent
5db6df4fc2
commit
45f8e31f1a
1 changed files with 20 additions and 0 deletions
|
|
@ -643,6 +643,26 @@ const Player = ({ urlParams, queryParams }) => {
|
||||||
navigator.mediaSession.setActionHandler('nexttrack', nexVideoCallback);
|
navigator.mediaSession.setActionHandler('nexttrack', nexVideoCallback);
|
||||||
}, [player.nextVideo, onPlayRequested, onPauseRequested, onNextVideoRequested]);
|
}, [player.nextVideo, onPlayRequested, onPauseRequested, onNextVideoRequested]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const onMediaKey = (action) => {
|
||||||
|
switch (action) {
|
||||||
|
case 'play-pause':
|
||||||
|
video.state.paused ? onPlayRequested() : onPauseRequested();
|
||||||
|
break;
|
||||||
|
case 'next-track':
|
||||||
|
onNextVideoRequested();
|
||||||
|
break;
|
||||||
|
case 'previous-track':
|
||||||
|
if (video.state.time !== null && video.state.time > 5000) {
|
||||||
|
onSeekRequested(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
shell.on('media-key', onMediaKey);
|
||||||
|
return () => shell.off('media-key', onMediaKey);
|
||||||
|
}, [video.state.paused, video.state.time, onPlayRequested, onPauseRequested, onNextVideoRequested, onSeekRequested]);
|
||||||
|
|
||||||
onShortcut('seekForward', (combo) => {
|
onShortcut('seekForward', (combo) => {
|
||||||
if (video.state.time !== null) {
|
if (video.state.time !== null) {
|
||||||
const seekDuration = combo === 1 ? settings.seekShortTimeDuration : settings.seekTimeDuration;
|
const seekDuration = combo === 1 ? settings.seekShortTimeDuration : settings.seekTimeDuration;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue