mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-02 19:01:40 +00:00
simplify remote/media session (#632)
This commit is contained in:
parent
d57b4b4b68
commit
110a1a63f0
15 changed files with 236 additions and 230 deletions
39
src/renderer/features/player/update-remote-song.tsx
Normal file
39
src/renderer/features/player/update-remote-song.tsx
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import isElectron from 'is-electron';
|
||||
import { QueueSong } from '/@/renderer/api/types';
|
||||
|
||||
const remote = isElectron() ? window.electron.remote : null;
|
||||
const mediaSession = navigator.mediaSession;
|
||||
|
||||
export const updateSong = (song: QueueSong | undefined) => {
|
||||
if (mediaSession) {
|
||||
let metadata: MediaMetadata;
|
||||
|
||||
if (song?.id) {
|
||||
let artwork: MediaImage[];
|
||||
|
||||
if (song.imageUrl) {
|
||||
const image300 = song.imageUrl
|
||||
?.replace(/&size=\d+/, '&size=300')
|
||||
.replace(/\?width=\d+/, '?width=300')
|
||||
.replace(/&height=\d+/, '&height=300');
|
||||
|
||||
artwork = [{ sizes: '300x300', src: image300, type: 'image/png' }];
|
||||
} else {
|
||||
artwork = [];
|
||||
}
|
||||
|
||||
metadata = new MediaMetadata({
|
||||
album: song.album ?? '',
|
||||
artist: song.artistName,
|
||||
artwork,
|
||||
title: song.name,
|
||||
});
|
||||
} else {
|
||||
metadata = new MediaMetadata();
|
||||
}
|
||||
|
||||
mediaSession.metadata = metadata;
|
||||
}
|
||||
|
||||
remote?.updateSong(song);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue