add mediasession info

This commit is contained in:
2024-01-18 13:01:42 +01:00
parent bade38efc6
commit 4ee4b697cb
2 changed files with 15 additions and 4 deletions

View File

@@ -1,8 +1,8 @@
import { writable } from 'svelte/store';
import { writable, get } from 'svelte/store';
import { browser } from '$app/environment';
export const currentStream = writable({});
export const currentSongIndex = writable(0);
export const currentSongIndex = writable(null);
export const favoritedStreams = writable(
new Set(JSON.parse((browser && localStorage.getItem('favoritedStreams')) || '[]'))
@@ -12,6 +12,18 @@ if (browser) {
favoritedStreams.subscribe((val) => {
localStorage.setItem('favoritedStreams', JSON.stringify(Array.from(val)));
});
if ('mediaSession' in navigator) {
currentSongIndex.subscribe((val) => {
if (val != null) {
const song = get(currentStream).tracks[val];
navigator.mediaSession.metadata = new MediaMetadata({
artist: song[1],
title: song[2]
});
}
});
}
}
export const tagList = [