Skip to content

Commit

Permalink
Set media metadata when sample is playing
Browse files Browse the repository at this point in the history
See #109
  • Loading branch information
Mesoptier committed Mar 9, 2024
1 parent 5f60a96 commit 3569c18
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions frontend/helpers/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ class Player extends TypedEventTarget<PlayerEvents> {
`ended ${key}`,
new Event(`ended ${key}`),
);

if (this.playing.size === 0 && 'mediaSession' in navigator) {
navigator.mediaSession.playbackState = 'none';
navigator.mediaSession.metadata = null;
}
}
};

Expand All @@ -328,6 +333,14 @@ class Player extends TypedEventTarget<PlayerEvents> {
}

await audio.play();

if ('mediaSession' in navigator) {
navigator.mediaSession.playbackState = 'playing';
navigator.mediaSession.metadata = new MediaMetadata({
title: sample.name,
artist: sample.categories.join(' / '),
});
}
} catch (error) {
handleStop();

Expand Down

0 comments on commit 3569c18

Please sign in to comment.