]> littlesong.place Git - littlesongplace.git/commitdiff
Add Media Session integration
authorChris Fulljames <christianfulljames@gmail.com>
Thu, 30 Jan 2025 12:36:16 +0000 (07:36 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Thu, 30 Jan 2025 12:36:16 +0000 (07:36 -0500)
static/player.js
todo.txt

index 9b37b92a7c49ab6d4792ed43cc8d7699456a26af..572b2bf9ab96bf81997f2182153fa43458064b0d 100644 (file)
@@ -7,7 +7,6 @@ function play(event) {
     while (!songElement.classList.contains("song"))
     {
         songElement = songElement.parentElement;
-        console.log(songElement);
     }
     m_songIndex = m_allSongs.indexOf(songElement);
     playCurrentSong();
@@ -15,7 +14,6 @@ function play(event) {
 
 function playCurrentSong() {
     var song = m_allSongs[m_songIndex];
-    console.log(song);
     var songData = JSON.parse(song.dataset.song);
 
     var player = document.getElementById("player")
@@ -37,6 +35,30 @@ function playCurrentSong() {
     artist.textContent = songData.username;
     artist.href = `/users/${songData.username}`;
     artist.hidden = false;
+
+    if ("mediaSession" in navigator) {
+        navigator.mediaSession.metadata = new MediaMetadata({
+            title: songData.title,
+            artist: songData.username,
+            album: "Little Song Place",
+            artwork: [{src: "/static/lsp_notes.png"}],
+        });
+        navigator.mediaSession.setActionHandler('nexttrack', () => {
+            songNext();
+        });
+
+        navigator.mediaSession.setActionHandler('previoustrack', () => {
+            songPrevious();
+        });
+
+        navigator.mediaSession.setActionHandler('play', async () => {
+            songPlayPause();
+        });
+
+        navigator.mediaSession.setActionHandler('pause', () => {
+            songPlayPause();
+        });
+    }
 }
 
 // Play or pause the current song in the player
@@ -176,7 +198,6 @@ document.addEventListener("DOMContentLoaded", (event) => {
 
     // Song queue
     for (const element of document.getElementsByClassName("song")) {
-        console.log(element);
         m_allSongs.push(element);
     }
 });
index ff6466a58c52d2382b653be68492583d8bdc925a..fcf51ca496ca6d3b93f7bb5b11f16c3913973737 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -6,6 +6,7 @@
 - Additional song info in player (collabs, description, tags)
 - Tips and Tricks (or html helper for bio/descriptions?)
 - Multiline/html descriptions
+- Profile pictures
 - Dark mode/site color customization
 - Admin accounts
 - Account deletion