mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-01-11 22:40:31 +00:00
feat(Player): add media session support
This commit is contained in:
parent
27b6942fcd
commit
5340d6d0d9
1 changed files with 38 additions and 0 deletions
|
|
@ -459,6 +459,44 @@ const Player = ({ urlParams, queryParams }) => {
|
|||
};
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
if ('mediaSession' in navigator && player.metaItem?.type === 'Ready') {
|
||||
navigator.mediaSession.metadata = new MediaMetadata({
|
||||
title: 'Stremio',
|
||||
artist: player.title,
|
||||
artwork: [{
|
||||
src: player.metaItem.content.poster
|
||||
}]
|
||||
});
|
||||
}
|
||||
}, [player.metaItem, player.title]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if ('mediaSession' in navigator) {
|
||||
navigator.mediaSession.setActionHandler('play', () => {
|
||||
onPlayRequested();
|
||||
});
|
||||
|
||||
navigator.mediaSession.setActionHandler('pause', () => {
|
||||
onPauseRequested();
|
||||
});
|
||||
|
||||
navigator.mediaSession.setActionHandler('stop', () => {
|
||||
onPauseRequested();
|
||||
});
|
||||
|
||||
navigator.mediaSession.setActionHandler('nexttrack', () => {
|
||||
onNextVideoRequested();
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
if ('mediaSession' in navigator) {
|
||||
navigator.mediaSession.playbackState = video.state.paused ? 'paused' : 'playing';
|
||||
}
|
||||
}, [video.state.paused]);
|
||||
|
||||
React.useLayoutEffect(() => {
|
||||
const onKeyDown = (event) => {
|
||||
switch (event.code) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue