diff --git a/app/src/components/Common.js b/app/src/components/Common.js index e4c9d5af..25706641 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -1272,6 +1272,23 @@ export function HotspotStatusIcon() { } +export function useMediaSession(title, artist, artworkUrl) { + useEffect(() => { + if ('mediaSession' in navigator && title) { + const artwork = []; + if (artworkUrl) { + artwork.push({src: artworkUrl, type: 'image/jpeg'}); + } + + navigator.mediaSession.metadata = new MediaMetadata({ + title: title, + artist: artist || '', + artwork: artwork, + }); + } + }, [title, artist, artworkUrl]); +} + export function useTitle(title) { const documentDefined = typeof document !== 'undefined'; const originalTitle = React.useRef(documentDefined ? document.title : null); diff --git a/app/src/components/VideoPlayer.js b/app/src/components/VideoPlayer.js index 525cf2c1..90765bc1 100644 --- a/app/src/components/VideoPlayer.js +++ b/app/src/components/VideoPlayer.js @@ -14,6 +14,7 @@ import { MultilineText, PageContainer, PreviewPath, + useMediaSession, useTitle } from "./Common"; import Grid from "semantic-ui-react/dist/commonjs/collections/Grid"; @@ -210,6 +211,10 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) { const {channel} = useChannel(video && video.channel_id ? video.channel_id : channelId); const {comments, captions} = useVideoExtras(videoFile?.video?.id); + const mediaTitle = videoFile ? (videoFile.title || videoFile.stem || videoFile.name) : null; + const mediaArtworkUrl = video && video.poster_path ? `${MEDIA_PATH}/${encodeMediaPath(video.poster_path)}` : null; + useMediaSession(mediaTitle, channel ? channel.name : null, mediaArtworkUrl); + // Keyboard shortcuts for video player controls // k: Play/pause useHotkeys('k', () => {