• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Simple Music Player Module

Scheduled Pinned Locked Moved Entertainment
musicaudioplayer
41 Posts 19 Posters 48.2k Views 21 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    DrCastor
    last edited by yawns Oct 16, 2017, 7:42 PM Oct 16, 2017, 4:40 PM

    Ok, found bad speakers, but at least, they allow me to test it. It works :). I’m a real noob, so some useless things may still be there. But at least, it will do the trick

    Go to the node_helper.js file, and change it this way:

    var Class = require("../../js/class.js");
    var express = require("express");
    var path = require("path");
    
    
    module.exports = NodeHelper.create({
    
    	init: function() {
    		console.log("Initializing mm-music-player module helper ...");
    	},
    
    	start: function() {
    		this.expressApp.get('/music', function (req, res) {
    			var fs = require('fs');
    			var path = require('path');
    
    			var files = [];
    
    			fs.readdir('modules/mm-music-player/music', (err, data) => {
    				for(i = 0; i < data.length; i++){
    					if(path.extname(data[i]) == ".mp3"){
    						files.push(data[i]);
    					}
    				}
    				
    				res.send(files);
    			});
    		});
    	},
    
    
    
    	/* setExpressApp(app)
    	 * Sets the express app object for this module.
    	 * This allows you to host files from the created webserver.
    	 *
    	 * argument app Express app - The Express app object.
    	 */
    	setExpressApp: function(app) {
    		this.expressApp = app;
    
    		var publicPath = this.path + "/public";
    		app.use("/" + this.name, express.static(publicPath));
    	},
    
    });
    

    If luck is by your side, it will work ;)

    A 1 Reply Last reply Oct 16, 2017, 5:00 PM Reply Quote 0
    • A Offline
      aro28 @DrCastor
      last edited by yawns Oct 16, 2017, 7:42 PM Oct 16, 2017, 5:00 PM

      @DrCastor said in Simple Music Player Module:

      Hi,
      Could you please send a full code of “node_helper.js” file?
      Thanks in advance,

      1 Reply Last reply Reply Quote 0
      • D Offline
        DrCastor
        last edited by Oct 16, 2017, 6:42 PM

        It seems that I don’t have enough priviledges for uploading a file directly in this reply, and I don’t really want to provide you a link to some uploading site, since I don’t know if it is allowed in the rules of this site. I’ll try to find a way.

        Since then, just try what I told you. You juste have to cut and paste what I wrote. I’m sure you can do it, be confident in yourself ;)

        A 1 Reply Last reply Oct 17, 2017, 2:56 PM Reply Quote 0
        • A Offline
          aro28 @DrCastor
          last edited by Oct 17, 2017, 2:56 PM

          @DrCastor
          Manay thanks!
          Resolved.

          1 Reply Last reply Reply Quote 0
          • D Offline
            DrCastor
            last edited by Oct 17, 2017, 3:01 PM

            Happy to have helped you :). It is sad that just for a problem of syntax, the source file was never edited :$

            A 1 Reply Last reply Oct 17, 2017, 5:49 PM Reply Quote 0
            • A Offline
              aro28 @DrCastor
              last edited by Oct 17, 2017, 5:49 PM

              @DrCastor

              Last question.
              Do you know how to write a code for a volume buttons for that player?
              I know that “MMM-TouchPlayerBasic” module has that feature.

              1 Reply Last reply Reply Quote 0
              • D Offline
                DrCastor
                last edited by Oct 18, 2017, 7:14 AM

                no, I’m a noob in this. You should take a look at the files of MMM-TouchPlayerBasic, and try to enderstand how the volume is managed. Good luck!

                1 Reply Last reply Reply Quote 0
                • M Offline
                  Milk
                  last edited by Oct 29, 2017, 9:18 PM

                  would it be possible to make it so I could use a keyboard to control the music?

                  A 1 Reply Last reply Oct 30, 2017, 5:19 PM Reply Quote 0
                  • A Offline
                    aro28 @Milk
                    last edited by Oct 30, 2017, 5:19 PM

                    @Milk
                    I use the built-in Monitor’s hard buttons to control the sound.
                    There’s “alsamixer” command to control volume. But this is not convenient.

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      Milk
                      last edited by Nov 3, 2017, 8:23 PM

                      			'use strict';
                      			var playingnow = false;
                      			document.addEventListener('keypress', (event) => {
                      				const keyName = event.key;
                      				
                      				if(keyName == " " && playingnow == false){
                      					$(audioElement).trigger('play');
                      					$(currentlyPlaying).html(songs[current]).fadeIn(fadeDuriation);
                      					playingnow = true;
                      				
                      				}else if(keyName == " " && playingnow == true){
                      					$(audioElement).trigger('pause');
                      					$(currentlyPlaying).fadeOut(fadeDuriation);
                      					playingnow = false;
                      				
                      				}
                      				if(keyName == "."){
                      					next();
                      				}
                      				if(keyName == ","){
                      					back();
                      				}
                      			});
                      

                      I have added this code to the mm-music player.js and it now accepts key presses

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 5
                      • 4 / 5
                      • First post
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy