<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MP3 Player]]></title><description><![CDATA[<p dir="auto">Hi there</p>
<p dir="auto">I am tyring to modify this mp3 player module: <a href="https://github.com/justjim1220/MMM-MP3Player" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/justjim1220/MMM-MP3Player</a></p>
<p dir="auto">and I am trying to make it more nicer by trying to mimic this music player:</p>
<p dir="auto"><a href="https://codepen.io/letea/pen/egmazy" target="_blank" rel="noopener noreferrer nofollow ugc">https://codepen.io/letea/pen/egmazy</a></p>
<p dir="auto">What I am struggling with is, is it possible to make a module on magicmirror using html code? because the one from codepen uses html and I am not sure how I can do that?</p>
<p dir="auto">Any help or guidance will be very much appreciated.</p>
<p dir="auto">Thanks.</p>
]]></description><link>https://forum.magicmirror.builders/topic/18647/mp3-player</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 19:29:51 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/18647.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Apr 2024 11:36:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MP3 Player on Tue, 23 Dec 2025 10:17:32 GMT]]></title><description><![CDATA[<p dir="auto">Hey <a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a>, I’ve been following your progress with the folder nesting—it’s a tricky bit of logic to get right in the node_helper, but it’ll be worth it for the cleaner UI!<br />
One thing I noticed while setting up my own music module is that the player looks a lot better if the MP3 metadata (ID3 tags) is actually clean. If the tags are messy, the ‘Artist’ and ‘Title’ fields on the mirror usually end up looking like a jumble of underscores and file extensions.<br />
Since you’re organizing a big library right now, I’ve been using <a href="https://editmp3tags.com/" target="_blank" rel="noopener noreferrer nofollow ugc">https://editmp3tags.com/</a> to quickly fix the tags in the browser before dropping them into the music folder. It’s way faster than using a heavy desktop app and helps the module display everything correctly once you get that ‘better method’ logic sorted out.</p>
]]></description><link>https://forum.magicmirror.builders/post/129317</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/129317</guid><dc:creator><![CDATA[BiaGen]]></dc:creator><pubDate>Tue, 23 Dec 2025 10:17:32 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 18:08:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> I’m pretty sure the module used a node_helper</p>
<p dir="auto">now if you make it a url, then you can fetch it thru the browser…  but the server side is actually reading  the file</p>
<p dir="auto">but you could make it a file url</p>
<p dir="auto">file:///server/path to file</p>
<p dir="auto">in MagicMirror the server  home folder is the MagicMirror folder</p>
]]></description><link>https://forum.magicmirror.builders/post/117144</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117144</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 19 Apr 2024 18:08:20 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 16:55:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> said in <a href="/post/117141">MP3 Player</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> said in <a href="/post/117138">MP3 Player</a>:</p>
<blockquote>
<p dir="auto">fs.readdir(musicFolder, (err, files) =&gt; {</p>
</blockquote>
<p dir="auto">the modulename.js that runs in the browser cannot read files directly, due to security restrictions ( any script could read ALL your files without you knowing)</p>
<p dir="auto">this is why the node_helper exists…</p>
</blockquote>
<p dir="auto">so whats the alternative? I had this MMM-QuranPlayer module that was able to read mp3 files from the folders in the “public” directory which was located in the root folder of the module.</p>
]]></description><link>https://forum.magicmirror.builders/post/117142</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117142</guid><dc:creator><![CDATA[bachoo786]]></dc:creator><pubDate>Fri, 19 Apr 2024 16:55:20 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 16:47:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> said in <a href="/post/117138">MP3 Player</a>:</p>
<blockquote>
<p dir="auto">fs.readdir(musicFolder, (err, files) =&gt; {</p>
</blockquote>
<p dir="auto">the modulename.js that runs in the browser cannot read files directly, due to security restrictions ( any script could read ALL your files without you knowing)</p>
<p dir="auto">this is why the node_helper exists…</p>
]]></description><link>https://forum.magicmirror.builders/post/117141</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117141</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 19 Apr 2024 16:47:00 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 16:43:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> you could say, I have updated the repo, git pull to get the changes…</p>
<p dir="auto">you need to<br />
git add,<br />
git commit -m and<br />
git push<br />
to update the repo</p>
]]></description><link>https://forum.magicmirror.builders/post/117140</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117140</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 19 Apr 2024 16:43:53 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 16:41:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a></p>
<p dir="auto">I changed from this:</p>
<pre><code>if (MP3.config.musicData) {
        const musicList = MP3.createElement("ul", "musicList", "musicList");

        MP3.config.musicData.forEach(folderData =&gt; {
            // Folder item
            const folderItem = MP3.createElement("li", "folderItem", `folderItem-${folderData.folderName}`);
            folderItem.innerHTML = `
                &lt;span class="folderName"&gt;${folderData.folderName}&lt;/span&gt;
                &lt;i class="fa fa-chevron-down"&gt;&lt;/i&gt; 
            `; 

            // Songs list within the folder
            const songsList = MP3.createElement("ul", "songsList", `songsList-${folderData.folderName}`);
            songsList.style.display = 'none'; // Initially hide the songs list

            folderData.songs.forEach(song =&gt; {
                const songItem = MP3.createElement("li", "songItem", `songItem-${song}`);
                songItem.innerHTML = song.substr(0, song.length - 4); 
                songsList.appendChild(songItem);
            });

            // Click event listeners
            folderItem.addEventListener('click', () =&gt; {
                songsList.style.display = songsList.style.display === 'none' ? 'block' : 'none'; // Toggle display
                folderItem.querySelector('.fa').classList.toggle('fa-chevron-down');
                folderItem.querySelector('.fa').classList.toggle('fa-chevron-up');
            });

            songsList.addEventListener('click', (event) =&gt; {
                const clickedSongItem = event.target;
                if (clickedSongItem.classList.contains('songItem')) {
                    const songName = clickedSongItem.innerText;
                    const folderName = folderData.folderName;
                    MP3.playSong(folderName, songName);
                }
            });

            folderItem.appendChild(songsList);
            musicList.appendChild(folderItem);
        });
</code></pre>
<p dir="auto">to this:</p>
<pre><code>if (MP3.config.musicData) {
   const fs = require('fs');
   const path = require('path');

   const musicFolder = path.resolve(MP3.config.musicData.musicPath);
   const supportedExtensions = this.defaults.extensions; // Use module's default extensions

   fs.readdir(musicFolder, (err, files) =&gt; {
    if (err) {
     console.error("Error reading music directory:", err);
     // Handle the error - display message to user, etc. 
    } else {
     const musicFiles = files.filter(file =&gt; supportedExtensions.includes(path.extname(file).toLowerCase()));

     if (musicFiles.length &gt; 0) {
      const musicList = MP3.createElement("ul", "musicList");

      musicFiles.forEach(musicFile =&gt; {
       const songItem = MP3.createElement('li', 'songItem');
       songItem.innerHTML = musicFile.substr(0, musicFile.length - 4); 
       songItem.addEventListener('click', () =&gt; {
        MP3.playSong(musicFile); // Assuming you want to play the song directly
       });
       musicList.appendChild(songItem);
      });
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/117138</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117138</guid><dc:creator><![CDATA[bachoo786]]></dc:creator><pubDate>Fri, 19 Apr 2024 16:41:25 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 15:57:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> well, coding is a challenge sometimes</p>
<p dir="auto">you changed the data coming back from the node helper</p>
<p dir="auto">the code is looking for songs<br />
but its a nested struct in musicData</p>
<p dir="auto">so, fix the first thing (the socketNotificationReceived)<br />
and then the code crashes later cause you are expecting the data in songs…</p>
<p dir="auto">computers do things fast… they don’t know WHY they are doing it, so can’t ‘fix’ themselves</p>
]]></description><link>https://forum.magicmirror.builders/post/117136</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117136</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 19 Apr 2024 15:57:13 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 15:49:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> what did you change?</p>
<p dir="auto">this is a missing } probably</p>
]]></description><link>https://forum.magicmirror.builders/post/117135</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117135</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 19 Apr 2024 15:49:13 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 15:49:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> so I made a mistake, i wanted my code to look for the mp3 files automatically in the folders within the music directory.</p>
<p dir="auto">currently I am getting an error in the developer console:</p>
<pre><code>Uncaught SyntaxError: Unexpected token ',' (at MMM-MP3Player.js:184:2)
</code></pre>
<p dir="auto">its the “,” at the end of</p>
<pre><code>return wrapper
</code></pre>
<p dir="auto">I am trying to have one ‘music’ folder with subfolders for each artist containing their songs. This way, the module would display artists on the frontend, and clicking an artist’s name would show the songs in their folder, and click on the song would then play the mp3 file.</p>
<p dir="auto">feel like giving up really even though I think I am close</p>
]]></description><link>https://forum.magicmirror.builders/post/117134</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117134</guid><dc:creator><![CDATA[bachoo786]]></dc:creator><pubDate>Fri, 19 Apr 2024 15:49:00 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 15:42:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> you don’t set</p>
<pre><code>if (MP3.config.musicData) {  anywhere..  so getDom() returns an empty div
</code></pre>
<p dir="auto">I ‘assume’ you meant for the node_helper to send this back</p>
<p dir="auto">but yours socketNotifcationReceived does this</p>
<pre><code class="language-js">    if(notification === "RETURNED_MUSIC")
      MP3.config.songs = payload.songs;  &lt;---  songs is undefined, but musicData is there
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/117133</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117133</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 19 Apr 2024 15:42:58 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 15:24:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> here is the repo:</p>
<p dir="auto"><a href="https://github.com/bachoo786/MMM-MP3Player" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/bachoo786/MMM-MP3Player</a></p>
]]></description><link>https://forum.magicmirror.builders/post/117132</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117132</guid><dc:creator><![CDATA[bachoo786]]></dc:creator><pubDate>Fri, 19 Apr 2024 15:24:31 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 13:47:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> well, code and data don’t match</p>
<p dir="auto">config.js</p>
<pre><code>        musicPath: "modules/MMM-MP3Player/music",
</code></pre>
<p dir="auto">defaults</p>
<pre><code>    musicPath: "modules/MMM-MP3Player/music",
</code></pre>
<p dir="auto">getDom()</p>
<pre><code>    if (MP3.config.musicData) { (and other places) 
</code></pre>
<p dir="auto">if you use the developers window you can step thru the code</p>
]]></description><link>https://forum.magicmirror.builders/post/117131</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117131</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 19 Apr 2024 13:47:34 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 13:39:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> I will .</p>
<p dir="auto">Nothing says everything is loaded including the mp3 player module.</p>
]]></description><link>https://forum.magicmirror.builders/post/117130</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117130</guid><dc:creator><![CDATA[bachoo786]]></dc:creator><pubDate>Fri, 19 Apr 2024 13:39:58 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 13:16:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> what shows in the developers window?</p>
]]></description><link>https://forum.magicmirror.builders/post/117129</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117129</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 19 Apr 2024 13:16:00 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 13:09:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> can you please  make a git repo of this.</p>
]]></description><link>https://forum.magicmirror.builders/post/117128</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117128</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 19 Apr 2024 13:09:17 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 13:00:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a>  sorry to mess with your head but I have been working on this for the last 3 hours and have come up with the following that should show the folders on the front end and when any folder is clicked it should reveal the mp3 files. the issue I am facing is that I am having no errors whatsoever but the module will just not show on the front end. I am pulling my hair out now !</p>
<p dir="auto">these are my files:</p>
<p dir="auto">node_helper.js:</p>
<pre><code>var NodeHelper = require('node_helper');
const Fs = require('fs');

module.exports = NodeHelper.create({
    start: function() {
        console.log("Loaded MP3Player node_helper");
    },

    socketNotificationReceived: function(notification, payload) {
        var self = this;
        if (notification === 'SOURCE_MUSIC') {
            const musicPath = payload.musicPath;
            const extensions = payload.extensions;

            Fs.readdir(musicPath, (err, folders) =&gt; {
                if (err) {
                    console.error("Error reading music directory:", err);
                    self.sendSocketNotification('ERROR', {message: "Error reading music directory"});
                } else {
                    const musicData = folders.map(folder =&gt; ({
                        folderName: folder,
                        songs: Fs.readdirSync(`${musicPath}/${folder}`).filter(file =&gt; self.checkExt(file, extensions))
                    }));
                    self.sendSocketNotification("RETURNED_MUSIC", { musicData: musicData }); 
                }
            });
        }
    },

    checkExt: function(file, ext) {
        return ext.some(extension =&gt; file.toLowerCase().endsWith(extension)); 
    }
});
</code></pre>
<p dir="auto">MMM-MP3Player.js:</p>
<pre><code>var MP3;
var substr;
Module.register("MMM-MP3Player", {
  defaults: {
    songs: [],
    musicPath: "modules/MMM-MP3Player/music",
    extensions: ["mp3", "wma", "acc", "ogg"],
    songs: null,
    autoPlay: false,
    random: false,
  },
  audio: null,
  songTitle: null,
  mediaPlayer: null,
  dataAvailable: true,
  curSong :0,
  curLength : 0,
  time: null,
  play: null,
  firstTime: true,
  substr: null,
  
  getStyles: function(){
    return ["MMM-MP3Player.css", "font-awesome.css"];
  },

  start: function(){
    MP3 = this;
    console.log("autoPlay configuration:", MP3.config.autoPlay);
    Log.info("Starting module: " + MP3.name);
  },

getDom: function() {
    var wrapper = document.createElement("div");

    if (MP3.config.musicData) {
        const musicList = MP3.createElement("ul", "musicList", "musicList");

        MP3.config.musicData.forEach(folderData =&gt; {
            // Folder item
            const folderItem = MP3.createElement("li", "folderItem", `folderItem-${folderData.folderName}`);
            folderItem.innerHTML = `
                &lt;span class="folderName"&gt;${folderData.folderName}&lt;/span&gt;
                &lt;i class="fa fa-chevron-down"&gt;&lt;/i&gt; 
            `; 

            // Songs list within the folder
            const songsList = MP3.createElement("ul", "songsList", `songsList-${folderData.folderName}`);
            songsList.style.display = 'none'; // Initially hide the songs list

            folderData.songs.forEach(song =&gt; {
                const songItem = MP3.createElement("li", "songItem", `songItem-${song}`);
                songItem.innerHTML = song.substr(0, song.length - 4); 
                songsList.appendChild(songItem);
            });

            // Click event listeners
            folderItem.addEventListener('click', () =&gt; {
                songsList.style.display = songsList.style.display === 'none' ? 'block' : 'none'; // Toggle display
                folderItem.querySelector('.fa').classList.toggle('fa-chevron-down');
                folderItem.querySelector('.fa').classList.toggle('fa-chevron-up');
            });

            songsList.addEventListener('click', (event) =&gt; {
                const clickedSongItem = event.target;
                if (clickedSongItem.classList.contains('songItem')) {
                    const songName = clickedSongItem.innerText;
                    const folderName = folderData.folderName;
                    MP3.playSong(folderName, songName);
                }
            });

            folderItem.appendChild(songsList);
            musicList.appendChild(folderItem);
        });

        wrapper.appendChild(musicList); 

        // Add the rest of the existing code...
        MP3.mediaPlayer = MP3.createElement("div", "mediaPlayer", "mediaPlayer");
        MP3.audio = MP3.createElement("audio", "audioPlayer", "audioPlayer");
        MP3.audio.addEventListener("loadeddata", () =&gt; {
            MP3.dataAvailable = true;
            MP3.curLength = MP3.audio.duration;
            MP3.updateDurationLabel(); 
        }),
        MP3.audio.addEventListener("ended", () =&gt; {
            Log.log(" play ended")
            MP3.audio.currentTime = 0;
            if(MP3.config.autoPlay)
            {
                MP3.loadNext(MP3.config.random)
            }
            else
                MP3.mediaPlayer.classList.toggle("play");
        }),

MP3.audio.addEventListener("timeupdate", () =&gt; {
  MP3.updateDurationLabel();
}),
        MP3.mediaPlayer.appendChild(MP3.audio);

        // Add the rest of the controls to MP3.mediaPlayer
        var controls = MP3.createElement("div", "controls", false);
        MP3.songTitle = MP3.createElement("span", "title", "songTitle");
        MP3.setCurrentSong(MP3.curSong);
        controls.appendChild(MP3.songTitle);

        var discArea = MP3.createElement("div", "discarea", false);
        discArea.appendChild(MP3.createElement("div", "disc", false));
        var stylus = MP3.createElement("div", "stylus", false);
        stylus.appendChild(MP3.createElement("div", "pivot", false));
        stylus.appendChild(MP3.createElement("div", "arm", false));
        stylus.appendChild(MP3.createElement("div", "head", false));
        discArea.appendChild(stylus);
        MP3.mediaPlayer.appendChild(discArea);

      var buttons = MP3.createElement("div", "buttons", false);

      //  Previous Button
      var prev = MP3.createButton("back", "prevButton", "fa fa-backward");
      prev.addEventListener("click", () =&gt; {
        MP3.mediaPlayer.classList.toggle("play");
        MP3.dataAvailable = false;
        MP3.loadNext(MP3.config.random);
        MP3.audio.play();
        MP3.play.getElementsByTagName('i')[0].className = "fa fa-pause";
      }, false),
      buttons.appendChild(prev);

      //  Play Button
      MP3.play = MP3.createButton("play", "playButton", "fa fa-play");
      MP3.play.addEventListener("click", () =&gt; {
        MP3.mediaPlayer.classList.toggle("play");
        if (MP3.audio.paused) {
          setTimeout(() =&gt; {
            MP3.audio.play();
          }, 300);
          MP3.play.getElementsByTagName('i')[0].className = "fa fa-pause";
          MP3.timer = setInterval(MP3.updateDurationLabel, 100);
        } else {
          //MP3.loadNext(MP3.config.random);
          MP3.play.getElementsByTagName('i')[0].className = "fa fa-play";
          clearInterval(MP3.timer);
          MP3.audio.pause();
        }
      }, false);
      buttons.appendChild(MP3.play);

      //  Stop Button
      var stop = MP3.createButton("stop", "stopButton", "fa fa-stop");
      stop.addEventListener("click", () =&gt; {
        MP3.mediaPlayer.classList.remove("play");
        MP3.audio.pause();
        MP3.audio.currentTime = 0;
        MP3.play.getElementsByTagName('i')[0].className = "fa fa-play";
        MP3.updateDurationLabel();
      }, false);
      buttons.appendChild(stop);

      //  Next Button
      var next = MP3.createButton("next", "nextButton", "fa fa-forward");
      next.addEventListener("click", () =&gt; {
        MP3.mediaPlayer.classList.toggle("play");
        MP3.dataAvailable = false;
        MP3.loadNext(MP3.config.random);
        MP3.play.getElementsByTagName('i')[0].className = "fa fa-play";
      }, false);
      buttons.appendChild(next);

        controls.appendChild(buttons);

        var subControls = MP3.createElement("div", "subControls", false);
        var duration = MP3.createElement("span", "duration", "currentDuration");
        duration.innerHTML = "00:00" + "&amp;nbsp&amp;nbsp&amp;nbsp";
        subControls.appendChild(duration);

        var volumeSlider = MP3.createElement("input", "volumeSlider", "volumeSlider");
        volumeSlider.type = "range";
        volumeSlider.min = "0";
        volumeSlider.max = "1";
        volumeSlider.step = "0.01";
        volumeSlider.addEventListener("input", () =&gt; {
            MP3.audio.volume = parseFloat(volumeSlider.value);
        }, false);

        subControls.appendChild(volumeSlider);
        controls.appendChild(subControls);
        MP3.mediaPlayer.appendChild(controls);

        wrapper.appendChild(MP3.mediaPlayer);
    }

    if(MP3.firstTime &amp;&amp; MP3.config.autoPlay){
        console.log("First time and autoPlay are true. Setting firstTime to false.");
        MP3.firstTime=false;
    }
    return wrapper;
},

playSong: function(folderName, songName) {
    const songPath = MP3.config.musicPath + '/' + folderName + '/' + songName;
    MP3.audio.src = songPath; 
    MP3.songTitle.innerHTML = songName;
    MP3.audio.play();
},

  createElement: function(type, className, id){
    var elem = document.createElement(type);
    if(className) elem.className = className;
    if(id)  elem.id = id;
    return elem;
  },

  createButton: function(className, id, icon){
    var button = document.createElement('button');
    button.className = className;
    button.id = id;
    var ico = document.createElement("i");
    ico.className = icon;
    button.appendChild(ico);
    return button;
  },

updateDurationLabel: function() {
  var duration = document.getElementById('currentDuration');
  if (MP3.dataAvailable &amp;&amp; MP3.audio.duration &gt; 0) {
    duration.innerText = MP3.parseTime(MP3.audio.currentTime) + " / " + MP3.parseTime(MP3.audio.duration);
  } else {
    duration.innerText = "00:00 / 00:00";
  }
},

  parseTime: function(time){
    const minutes = Math.floor(time / 60)
    const seconds = Math.floor(time - minutes * 60)
    const secondsZero = seconds &lt; 10 ? "0" : ""
    const minutesZero = minutes &lt; 10 ? "0" : ""
    return minutesZero + minutes.toString() + ":" + secondsZero + seconds.toString()
  },
  
  setCurrentSong: function(index){
      if(MP3.audio!= undefined){
        MP3.audio.src = MP3.config.musicPath + '/' + MP3.config.songs[index];
        MP3.songTitle.innerHTML = MP3.config.songs[index].substr(0, MP3.config.songs[index].length - 4);
        MP3.curSong = index;
      }
  },
  loadNext: function(next){
   let index=0;
      console.log("loadNext: Autoplay:", MP3.config.autoPlay); // Add this line for logging
      MP3.audio.pause();
      if(next)  index= (MP3.curSong + 1) % MP3.config.songs.length;
      else      index = (MP3.curSong - 1) &lt; 0 ? MP3.config.songs.length - 1 : MP3.curSong - 1;
      MP3.setCurrentSong(index);
      MP3.audio.play();
  },

  notificationReceived: function (notification, payload) {
    if(notification === "ALL_MODULES_STARTED")
		  MP3.sendSocketNotification('SOURCE_MUSIC', MP3.config);
  },
  
  socketNotificationReceived: function(notification, payload){
    if(notification === "RETURNED_MUSIC")
      MP3.config.songs = payload.songs;
      // set the initial song index 
      MP3.setCurrentSong(0);
      // paint the player
      MP3.updateDom(2);
  },
});
</code></pre>
<p dir="auto">MMM-MP3Player.css:</p>
<pre><code>@import url("https://fonts.googleapis.com/css?family=Roboto"); /* Simpler, modern font */


.MMM-MP3Player .songInfo {
    flex: 1; /* Fill half of the available space */
    padding: 20px;
    font-family: 'Roboto', sans-serif;
}

.MMM-MP3Player .songTitle {
    font-size: 4em;
    font-weight: bold;
    color: #333; /* Darker text */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.MMM-MP3Player .container {
    position: relative; /* Add this if not present */
    /* ...other styles... */
}

.MMM-MP3Player .songsList {
    position: absolute;
    left: 10px; /* Adjust to align correctly, can be in px or % */
    top: -360px;  /* Adjust to align correctly, can be in px or % */
    width: 50%; /* Adjust to not exceed the container width */
    max-width: calc(100% - 40px); /* Subtract total horizontal padding */
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
    font-size: 2em;
    font-weight: bold;
    color: #FFF;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    z-index: 1000;
    background-image: 
        linear-gradient(
            to bottom,
            rgba(255, 255, 255, 0.8) 0%, 
            rgba(255, 255, 255, 0.75) 25%, 
            rgba(255, 255, 255, 0.6) 50%,
            rgba(255, 255, 255, 0.4) 75%,
            rgba(255, 255, 255, 0.3) 100%
        ),
        url('images/qsonglist.png');
    background-size: cover;
    background-position: center;    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.MMM-MP3Player .mediaPlayer {
    position: absolute;
    right: 0;  /* Adjust as needed to align to the right */
    top: -130px;       /* Aligns to the top of the container */
    width: 50%;   /* Or whatever width you require */
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
    justify-content: center;
    z-index: 1000; 
}


.MMM-MP3Player .controls {
    width: 80%;
    margin-top: 20px; 
}

.MMM-MP3Player .buttons button {
    background-color: #4CAF50; /* Example: Green for modern feel */
    color: white;
    border: none;
    border-radius: 50%;
    margin-right: 10px; 
    font-size: 1.2em;
    width: 50px;
    height: 50px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3); /* Adds depth */
}

.MMM-MP3Player .buttons button:hover {
    background-color: #3e8e41; /* Darker green on hover */
    cursor: pointer;
}
</code></pre>
<p dir="auto">in my config.js:</p>
<p dir="auto">I have added it this way:</p>
<pre><code>{
    module: "MMM-MP3Player",
    position: "bottom_center",
    "pages": {"Audio": "bottom_center"},
			config: {
				musicPath: "modules/MMM-MP3Player/music", 
				autoPlay: false,
				random: false,
				loopList: false,
			}
},
</code></pre>
<p dir="auto">Can you tell me what am I doing wrong? thanks</p>
]]></description><link>https://forum.magicmirror.builders/post/117127</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117127</guid><dc:creator><![CDATA[bachoo786]]></dc:creator><pubDate>Fri, 19 Apr 2024 13:00:43 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 12:17:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> ok. I saw the song list 2 and 3, and said<br />
these should be arrays of songlist[][]<br />
but now that u add by artist  it would be a hash of hashes<br />
songlist{artist{album}{song}}</p>
<p dir="auto">so you could access it with<br />
songlist[“artistname”][“album1”][song1"]</p>
<p dir="auto">or<br />
songlist[song_info]<br />
where song_info is a structure<br />
{ artist_name:“…”, albums[{name:“…”, songs:[{…}]]}</p>
]]></description><link>https://forum.magicmirror.builders/post/117126</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117126</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Fri, 19 Apr 2024 12:17:30 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Fri, 19 Apr 2024 09:42:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> ok I will try and explain the “better” method:</p>
<p dir="auto">I’m basically trying to add a playlist feature to the MP3 player module I’m working on. My initial setup involved adding a songList to MP3Player.js, which lists all the songs—.mp3 files—in the ‘music’ folder of the module. I’ve also added a second folder, ‘music2’, to categorize songs by artist. Each artist’s name is tagged with an ‘h2’ in the CSS, for both songList and songList2.</p>
<p dir="auto">However, this setup becomes cumbersome because it requires repeating the process for multiple artists, creating many folders and modifying the code each time for songList3, songList4, etc.</p>
<p dir="auto">I thought a better approach would be to have one ‘music’ folder with subfolders for each artist containing their songs. This way, the module would display artists on the frontend, and clicking an artist’s name would show the songs in their folder.</p>
<p dir="auto">I did start on this more streamlined method, but it proved challenging, so I reverted to the simpler, original method which we’ve been discussing since yesterday, as that uses a “single” songList displaying songs from the ‘music’ folder and has been working for me.  So I have been trying to add another “songList2” to add more artists and their respective music.</p>
<p dir="auto">I hope that makes sense?</p>
]]></description><link>https://forum.magicmirror.builders/post/117119</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117119</guid><dc:creator><![CDATA[bachoo786]]></dc:creator><pubDate>Fri, 19 Apr 2024 09:42:13 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Thu, 18 Apr 2024 18:51:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> I did not look at the better method… cause I don’t know what that means.</p>
<p dir="auto">I wasn’t looking at design, only syntax</p>
]]></description><link>https://forum.magicmirror.builders/post/117107</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117107</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Thu, 18 Apr 2024 18:51:07 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Thu, 18 Apr 2024 18:42:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> ah right so I need to change it to something like this:</p>
<pre><code>MP3.setCurrentSong(0, 'songName');
</code></pre>
<p dir="auto">Also did you manage to look into my later code which I described as the “better way”</p>
]]></description><link>https://forum.magicmirror.builders/post/117102</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117102</guid><dc:creator><![CDATA[bachoo786]]></dc:creator><pubDate>Thu, 18 Apr 2024 18:42:37 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Thu, 18 Apr 2024 17:05:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> yes,</p>
<p dir="auto">your function</p>
<pre><code>setCurrentSong: function(folderName, songName){
</code></pre>
<p dir="auto">takes two parms</p>
<p dir="auto">on line 264 you called it with one</p>
<pre><code>      MP3.setCurrentSong(0);
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/117089</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117089</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Thu, 18 Apr 2024 17:05:51 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Thu, 18 Apr 2024 17:01:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> ah thanks will look into it no need to apologise mate.</p>
<p dir="auto">Did you have a chance to look into my 2 sets of codes ?</p>
]]></description><link>https://forum.magicmirror.builders/post/117088</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117088</guid><dc:creator><![CDATA[bachoo786]]></dc:creator><pubDate>Thu, 18 Apr 2024 17:01:39 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Thu, 18 Apr 2024 16:51:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bachoo786" aria-label="Profile: bachoo786">@<bdi>bachoo786</bdi></a> sorry, been  out</p>
<p dir="auto">for editor,  install winsvp or bitwise ssh clients. I like bitwise better myself.</p>
<p dir="auto">both will give you ssh window AND a file manager  view from windows over the pi (other system) filesystem</p>
<p dir="auto">then you can double click to edit<br />
and save back.</p>
<p dir="auto">I use notepad++ or  visual studio code  as the editor. you  a  also install  visual studio code o  the  MagicMirror system,  UT then u need vnc or keyboard and mouse . I never edit ON the MagicMirror  system anymore</p>
]]></description><link>https://forum.magicmirror.builders/post/117087</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117087</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Thu, 18 Apr 2024 16:51:55 GMT</pubDate></item><item><title><![CDATA[Reply to MP3 Player on Thu, 18 Apr 2024 15:35:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a><br />
here is the code for trying out the “better” method:</p>
<p dir="auto">MMM-MP3Player.js:</p>
<pre><code>var MP3;
var substr;
Module.register("MMM-MP3Player", {
  defaults: {
    songs: [],
    musicPath: "modules/MMM-MP3Player/music",
    extensions: ["mp3", "wma", "acc", "ogg"],
    songs: null,
    autoPlay: false,
    random: false,
  },
  audio: null,
  songTitle: null,
  mediaPlayer: null,
  dataAvailable: true,
  curSong :0,
  curLength : 0,
  time: null,
  play: null,
  firstTime: true,
  substr: null,
  
  getStyles: function(){
    return ["MMM-MP3Player.css", "font-awesome.css"];
  },

  start: function(){
    MP3 = this;
    console.log("autoPlay configuration:", MP3.config.autoPlay);
    Log.info("Starting module: " + MP3.name);
  },

getDom: function(){
    var wrapper = document.createElement("div");

  if(MP3.config.folders) {
    var folderList = document.createElement("ul");
    folderList.className = "folderList";

    MP3.config.folders.forEach((folder, index) =&gt; {
      var folderItem = document.createElement("li");
      folderItem.className = "folderItem";
      folderItem.textContent = folder.name;
      folderItem.onclick = function() {
        this.classList.toggle("active");
        var songList = this.nextElementSibling;
        if (!songList) {
          songList = document.createElement("ul");
          songList.className = "songList";
          folder.songs.forEach(song =&gt; {
            var songItem = document.createElement("li");
            songItem.className = "songItem";
            songItem.textContent = song.substr(0, song.length - 4); // removes extension
            songItem.onclick = function() {
              // Set the song from the specific folder
              MP3.setCurrentSong(folder.name, song);
              MP3.audio.play();
              MP3.play.getElementsByTagName('i')[0].className = "fa fa-pause";
              MP3.mediaPlayer.classList.add("play");
              MP3.updateDurationLabel();
            };
            songList.appendChild(songItem);
          });
          this.parentNode.insertBefore(songList, this.nextSibling);
        } else {
          songList.parentNode.removeChild(songList);
        }
      };
      folderList.appendChild(folderItem);
    });
    wrapper.appendChild(folderList);
    
        // Add the rest of the existing code...
        MP3.mediaPlayer = MP3.createElement("div", "mediaPlayer", "mediaPlayer");
        MP3.audio = MP3.createElement("audio", "audioPlayer", "audioPlayer");
        MP3.audio.addEventListener("loadeddata", () =&gt; {
            MP3.dataAvailable = true;
            MP3.curLength = MP3.audio.duration;
            MP3.updateDurationLabel(); 
        }),
        MP3.audio.addEventListener("ended", () =&gt; {
            Log.log(" play ended")
            MP3.audio.currentTime = 0;
            if(MP3.config.autoPlay)
            {
                MP3.loadNext(MP3.config.random)
            }
            else
                MP3.mediaPlayer.classList.toggle("play");
        }),

MP3.audio.addEventListener("timeupdate", () =&gt; {
  MP3.updateDurationLabel();
}),
        MP3.mediaPlayer.appendChild(MP3.audio);

        // Add the rest of the controls to MP3.mediaPlayer
        var controls = MP3.createElement("div", "controls", false);
        MP3.songTitle = MP3.createElement("span", "title", "songTitle");
        MP3.setCurrentSong(MP3.curSong);
        controls.appendChild(MP3.songTitle);

        var discArea = MP3.createElement("div", "discarea", false);
        discArea.appendChild(MP3.createElement("div", "disc", false));
        var stylus = MP3.createElement("div", "stylus", false);
        stylus.appendChild(MP3.createElement("div", "pivot", false));
        stylus.appendChild(MP3.createElement("div", "arm", false));
        stylus.appendChild(MP3.createElement("div", "head", false));
        discArea.appendChild(stylus);
        MP3.mediaPlayer.appendChild(discArea);

      var buttons = MP3.createElement("div", "buttons", false);

      //  Previous Button
      var prev = MP3.createButton("back", "prevButton", "fa fa-backward");
      prev.addEventListener("click", () =&gt; {
        MP3.mediaPlayer.classList.toggle("play");
        MP3.dataAvailable = false;
        MP3.loadNext(MP3.config.random);
        MP3.audio.play();
        MP3.play.getElementsByTagName('i')[0].className = "fa fa-pause";
      }, false),
      buttons.appendChild(prev);

      //  Play Button
      MP3.play = MP3.createButton("play", "playButton", "fa fa-play");
      MP3.play.addEventListener("click", () =&gt; {
        MP3.mediaPlayer.classList.toggle("play");
        if (MP3.audio.paused) {
          setTimeout(() =&gt; {
            MP3.audio.play();
          }, 300);
          MP3.play.getElementsByTagName('i')[0].className = "fa fa-pause";
          MP3.timer = setInterval(MP3.updateDurationLabel, 100);
        } else {
          //MP3.loadNext(MP3.config.random);
          MP3.play.getElementsByTagName('i')[0].className = "fa fa-play";
          clearInterval(MP3.timer);
          MP3.audio.pause();
        }
      }, false);
      buttons.appendChild(MP3.play);

      //  Stop Button
      var stop = MP3.createButton("stop", "stopButton", "fa fa-stop");
      stop.addEventListener("click", () =&gt; {
        MP3.mediaPlayer.classList.remove("play");
        MP3.audio.pause();
        MP3.audio.currentTime = 0;
        MP3.play.getElementsByTagName('i')[0].className = "fa fa-play";
        MP3.updateDurationLabel();
      }, false);
      buttons.appendChild(stop);

      //  Next Button
      var next = MP3.createButton("next", "nextButton", "fa fa-forward");
      next.addEventListener("click", () =&gt; {
        MP3.mediaPlayer.classList.toggle("play");
        MP3.dataAvailable = false;
        MP3.loadNext(MP3.config.random);
        MP3.play.getElementsByTagName('i')[0].className = "fa fa-play";
      }, false);
      buttons.appendChild(next);

        controls.appendChild(buttons);

        var subControls = MP3.createElement("div", "subControls", false);
        var duration = MP3.createElement("span", "duration", "currentDuration");
        duration.innerHTML = "00:00" + "&amp;nbsp&amp;nbsp&amp;nbsp";
        subControls.appendChild(duration);

        var volumeSlider = MP3.createElement("input", "volumeSlider", "volumeSlider");
        volumeSlider.type = "range";
        volumeSlider.min = "0";
        volumeSlider.max = "1";
        volumeSlider.step = "0.01";
        volumeSlider.addEventListener("input", () =&gt; {
            MP3.audio.volume = parseFloat(volumeSlider.value);
        }, false);

        subControls.appendChild(volumeSlider);
        controls.appendChild(subControls);
        MP3.mediaPlayer.appendChild(controls);

        wrapper.appendChild(MP3.mediaPlayer);
    }

    if(MP3.firstTime &amp;&amp; MP3.config.autoPlay){
        console.log("First time and autoPlay are true. Setting firstTime to false.");
        MP3.firstTime=false;
    }
    return wrapper;
},

setCurrentSong: function(folderName, songName){
  if(MP3.audio!= undefined){
    MP3.audio.src = MP3.config.musicPath + '/' + folderName + '/' + songName;
    MP3.songTitle.innerHTML = songName.substr(0, songName.length - 4); // update song title display
    // Update the current song, handling file paths
    MP3.curSong = MP3.config.folders.findIndex(folder =&gt; folder.name === folderName);
  }
},

  createElement: function(type, className, id){
    var elem = document.createElement(type);
    if(className) elem.className = className;
    if(id)  elem.id = id;
    return elem;
  },

  createButton: function(className, id, icon){
    var button = document.createElement('button');
    button.className = className;
    button.id = id;
    var ico = document.createElement("i");
    ico.className = icon;
    button.appendChild(ico);
    return button;
  },

updateDurationLabel: function() {
  var duration = document.getElementById('currentDuration');
  if (MP3.dataAvailable &amp;&amp; MP3.audio.duration &gt; 0) {
    duration.innerText = MP3.parseTime(MP3.audio.currentTime) + " / " + MP3.parseTime(MP3.audio.duration);
  } else {
    duration.innerText = "00:00 / 00:00";
  }
},

  parseTime: function(time){
    const minutes = Math.floor(time / 60)
    const seconds = Math.floor(time - minutes * 60)
    const secondsZero = seconds &lt; 10 ? "0" : ""
    const minutesZero = minutes &lt; 10 ? "0" : ""
    return minutesZero + minutes.toString() + ":" + secondsZero + seconds.toString()
  },
  
  setCurrentSong: function(index){
      if(MP3.audio!= undefined){
        MP3.audio.src = MP3.config.musicPath + '/' + MP3.config.songs[index];
        MP3.songTitle.innerHTML = MP3.config.songs[index].substr(0, MP3.config.songs[index].length - 4);
        MP3.curSong = index;
      }
  },
  loadNext: function(next){
   let index=0;
      console.log("loadNext: Autoplay:", MP3.config.autoPlay); // Add this line for logging
      MP3.audio.pause();
      if(next)  index= (MP3.curSong + 1) % MP3.config.songs.length;
      else      index = (MP3.curSong - 1) &lt; 0 ? MP3.config.songs.length - 1 : MP3.curSong - 1;
      MP3.setCurrentSong(index);
      MP3.audio.play();
  },

  notificationReceived: function (notification, payload) {
    if(notification === "ALL_MODULES_STARTED")
		  MP3.sendSocketNotification('SOURCE_MUSIC', MP3.config);
  },
  
  socketNotificationReceived: function(notification, payload){
    if(notification === "RETURNED_MUSIC")
      MP3.config.songs = payload.songs;
      // set the initial song index 
      MP3.setCurrentSong(0);
      // paint the player
      MP3.updateDom(2);
  },
});
</code></pre>
<p dir="auto">and the updated node-helper.js:</p>
<pre><code>var NodeHelper = require('node_helper');
const Fs = require('fs');
const Path = require('path');

module.exports = NodeHelper.create({
  start: function() {
    console.log("Loaded MP3Player node_helper");
  },
  socketNotificationReceived: function(notification, payload){
    var self = this;
    if(notification == 'SOURCE_MUSIC'){
      var folders = this.getFoldersWithSongs(payload.musicPath, payload.extensions);
      self.sendSocketNotification("RETURNED_MUSIC", {folders: folders});
    }
  },
  getFoldersWithSongs: function(path, ext){
    var folders = [];
    var contents = Fs.readdirSync(path, { withFileTypes: true });
    contents.forEach(dirent =&gt; {
      if (dirent.isDirectory()) {
        let songFiles = Fs.readdirSync(Path.join(path, dirent.name))
                          .filter(file =&gt; this.checkExt(file, ext));
        if (songFiles.length &gt; 0) {
          folders.push({name: dirent.name, songs: songFiles});
        }
      }
    });
    console.log("mp3 player returning folder list with songs="+ folders)
    return folders;
  },
  checkExt: function(file, ext){
    return ext.some(extension =&gt; file.toLowerCase().endsWith("." + extension));
  }
});
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/117085</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/117085</guid><dc:creator><![CDATA[bachoo786]]></dc:creator><pubDate>Thu, 18 Apr 2024 15:35:07 GMT</pubDate></item></channel></rss>