add types
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
getSongAtTime,
|
||||
updateCurrentSong
|
||||
} from '$lib/stores.svelte.js';
|
||||
import type { Track } from '$lib/types';
|
||||
|
||||
interface Props {
|
||||
src: any;
|
||||
@@ -89,7 +90,7 @@
|
||||
// update browser metadata on track changes
|
||||
if ('mediaSession' in navigator) {
|
||||
currentSongIndex.subscribe((val) => {
|
||||
if (val != null && !paused) {
|
||||
if (val != null && !paused && $currentStream) {
|
||||
setMediaMetadata($currentStream.tracks[val]);
|
||||
}
|
||||
});
|
||||
@@ -111,7 +112,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function setMediaMetadata(track) {
|
||||
function setMediaMetadata(track: Track) {
|
||||
navigator.mediaSession.metadata = new MediaMetadata({
|
||||
artist: track[1],
|
||||
title: track[2]
|
||||
@@ -120,7 +121,7 @@
|
||||
|
||||
// browsers don't like if you update this while no media is playing
|
||||
function setMediaMetadataOnPlay() {
|
||||
if ('mediaSession' in navigator) {
|
||||
if ('mediaSession' in navigator && $currentStream && $currentSongIndex != null) {
|
||||
setMediaMetadata($currentStream.tracks[$currentSongIndex]);
|
||||
}
|
||||
}
|
||||
@@ -173,6 +174,7 @@
|
||||
}
|
||||
let bounds = songBar.getBoundingClientRect();
|
||||
let seekValue = ((event.pageX - bounds.left) * duration) / bounds.width;
|
||||
if (!$currentStream) return;
|
||||
let trackArray = $currentStream.tracks[getSongAtTime(seekValue)];
|
||||
seekTrack = trackArray[1] + ' - ' + trackArray[2];
|
||||
seekText = formatSeconds(seekValue);
|
||||
@@ -184,7 +186,9 @@
|
||||
if (volumeSeeking) seekVolume(event);
|
||||
}
|
||||
run(() => {
|
||||
updateCurrentSong(currentTime, $currentSongIndex);
|
||||
if ($currentSongIndex != null) {
|
||||
updateCurrentSong(currentTime, $currentSongIndex);
|
||||
}
|
||||
});
|
||||
run(() => {
|
||||
updateAudioAttributes(audio);
|
||||
|
||||
Reference in New Issue
Block a user