MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. zichao92
    3. Posts
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    Z
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 7
    • Posts 33
    • Groups 0

    Posts

    Recent Best Controversial
    • RE: youtube - Embedded YouTube on Your MagicMirror

      Hi @wizz ,

      I will look into your problem after my exams are over. =(
      I’ll reply you as soon as my exams have ended.

      posted in Entertainment
      Z
      zichao92
    • RE: youtube - Embedded YouTube on Your MagicMirror

      Hi @wizz ,

      It was designed to start up with the video loading after “DISPLAY=:0 npm start”. To hide the embedded video away, just press “show-all” from the remote control module

      posted in Entertainment
      Z
      zichao92
    • RE: youtube - Embedded YouTube on Your MagicMirror

      @djo

      Im finding a work around for your request. However, im a little busy with my school and assignments. I’ll look into it once Im free!

      posted in Entertainment
      Z
      zichao92
    • RE: youtube - Embedded YouTube on Your MagicMirror

      Hi @strawberry-3.141 ,

      What’s this “pr in the pipe” that you mentioned? Im interested in learning it.

      posted in Entertainment
      Z
      zichao92
    • RE: youtube - Embedded YouTube on Your MagicMirror

      Sorry im not too familiar with the guidelines. Thanks for amending them !

      Im a new user to GitHub as well. Do correct me if there are any errors.

      posted in Entertainment
      Z
      zichao92
    • youtube - Embedded YouTube on Your MagicMirror

      Description:

      Hi everyone,

      This is my first module development so please pardon me if i made any mistakes. This module allows you to play and control youtube video by using Jopyth’s Remote Control Module. This module wont be possible without the help of @Jopyth & @strawberry-3-141

      When you press “hide-all” under his Remote control module, the youtube video will appear and start playing.
      So the opposite will happen when you press “show-all”, youtube pause and disappears.

      P.S : Im relatively new to programming so please bear with me if I couldn’t understand your request.

      Screenshots:

      alt text
      alt text

      Download:

      [card:zichao92/youtube]

      posted in Entertainment
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      @strawberry-3.141

      OMG you are life saver. So the whole trick to my module is to use sendcommand instead?

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      Hi @strawberry-3.141 ,

      I just uploaded to github ( not too sure if i have done it correctly , first time using github) but here you go.

      https://github.com/zichao92/youtube/tree/Remote-

      Edit 1: I’m still using an older version of Remote Control module by Jopyth, it’s more stable on my MagicMirror( less laggy etc). Im not too sure why though

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      Hi @strawberry-3.141 ,
      Thanks for the clarification!
      I have added id = "my-vdieo" into my code, however, it produced another error :

      Uncaught TypeError: myPlayer.playVideo is not a function
          at Class.playthevideo (youtube.js:69)
      

      It’s not able to detect the function. After doing some readings about embedded YouTube videos, i came across this site :
      https://developers.google.com/youtube/js_api_reference#onYouTubePlayerReady

      It was mentioned that i require a callback function named onYouTubePlayerReady. The API will call this function when the player is fully loaded and the API is ready to receive calls.

      From there, I should be able to control my video. However, since this function can only be called in getDom function, im not too sure how it should work from here.

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      @strawberry-3.141 said in Controlling Embedded Youtube Video on MM:

      playthevideo: function() {
      //do the stuff
      }

      Hi there,

      I tried your recommendation but i got this error Uncaught TypeError: Cannot read property 'playVideo' of null.
      Which is coming from this code:

      playthevideo: function() {
      		var myPlayer = document.getElementById('my-video');
      		myPlayer.playVideo();
      		},
      

      I suspect that the problem is that the above function is not being recognise as my embedded youtube codes still lies in the getDom function, which has the allowscriptaccess="awalys" that allows the user to control the video. I tried to extract out from the getDom function but i think my syntax is wrong. Here’s the full code of the youtube function that’s in the getDom function.

      		wrapper.innerHTML='<div> <div>  //(youtube link here ) controls=0&showinfo=0&rel=0&autoplay=1" allowscriptaccess="always" name="my-video" frameborder="0" enablejsapi=1&version=3&playerapiid=ytplayer" type="application/x-shockwave-flash"> allowfullscreen></div></div>';
      
      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      @Jopyth ,

      I managed to have some developments with your remote control module’s sendNotifcation command. I hooked up the MM using a browser and observed( using dev console, Note to beginners: press F12 on a browser to access this cool feature ) that a notification was send from MM Remote. This means that you were right all along, just that i didnt know how to observe the sendNotification command via dev console.

      Currently, i have another issue. My youtube.js module receives the “PLAY_VIDEO” or “PAUSE_VIDEO” notification but is not able to perform what was desired.

      Here’s my snippet of my code from my youtube.js :

      notificationReceived: function(notification, payload) {
      		if (notification === "PAUSE_VIDEO"){
      			pausethevideo()
      
      		}
      		if (notification === "PLAY_VIDEO"){
      			playthevideo()
      
      		}
      	},
      
      getDom: function() {
      var wrapper = document.createElement("div");
      		wrapper.className = "thin xlarge bright";
      
      		function playthevideo(){
      		var myPlayer = document.getElementById('my-video');
      		myPlayer.playVideo();
      		};
      
      		function stopthevideo(){
      		var myPlayer = document.getElementById('my-video');
      		myPlayer.stopVideo();
      		};
      
      		function pausethevideo(){
      		var myPlayer = document.getElementById('my-video'); 
      		myPlayer.pauseVideo();
      		};
      		
      		
      		wrapper.innerHTML='<div> <div> allowfullscreen></div></div>'; //youtube video link found here.
      
      		
      
      			return wrapper;
      	}
      
      });
      

      However, i got an error from dev console :
      Uncaught TypeError: Cannot read property 'pauseVideo' of null at Class.notificationReceived (youtube.js:69)

      Im suspecting that my pauseVideo/playVideo function wasn’t recognised as it is getDom.

      Will appreciate any help or advice !

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      Hi all, im not too sure if i have made any mistake regarding the structure of MMM.

      I placed my notificationReceived at the front end of embedded youtube, which i called it youtube.js( it doesnt have any node_helper) :

      Here’s the code of my youtube.js , the codes are heavily based on a the default module called “compliments” :

      module.register("youtube",{
      
      	// Module config defaults.
      	defaults: {
      
      		updateInterval: 30000,
      		fadeSpeed: 4000
      	},
      
      
      
      	// Define required scripts.
      	getScripts: function() {
      		return ["moment.js"];
      //		exec("sudo python /home/pi/NicoRFID/RFID_playlist.py");
      	},
      	getStyles: function() {
      	    return [
      	        'script.css', // will try to load it from the vendor folder, otherwise it will load is from the module folder.
      	    ]
      	},
      
      	// Define start sequence.
      	start: function() {
      		Log.info("Starting module: " + this.name);
      
      		
      		// Schedule update timer.
      		var self = this;
      		setInterval(function() {
      			self.updateDom(self.config.fadeSpeed);
      		}, this.config.updateInterval);
      	},
      		
      
      		
      	/* randomIndex(compliments)
      	 * Generate a random index for a list of compliments.
      	 *
      	 * argument compliments Array - Array with compliments.
      	 *
      	 * return Number - Random index.
      	 */
      
      	/* complimentArray()
      	 * Retrieve an array of compliments for the time of the day.
      	 *
      	 * return compliments Array - Array with compliments for the time of the day.
      	 */
      	
      	/* complimentArray()
      	 * Retrieve a random compliment.
      	 *
      	 * return compliment string - A compliment.
      	 */
      		notificationReceived: function(notification, payload) {
      		if (notification === "PAUSE_VIDEO"){
      			pausethevideo()
      
      		}
      		else if (notification === "PLAY_VIDEO"){
      			playthevideo()
      
      		}
      	},
      
      
      	// Override dom generator.
      	getDom: function() {
      		//var complimentText = this.randomCompliment();
      		//var complimentText = "Hi NUS GOD Puay Hiang ";
      
      		//var compliment = document.createTextNode(complimentText);
      
      		var wrapper = document.createElement("div");
      		wrapper.className = "thin xlarge bright";
      
      		function playthevideo(){
      		var myPlayer = document.getElementById('my-video');
      		myPlayer.playVideo();
      		};
      
      		function stopthevideo(){
      		var myPlayer = document.getElementById('my-video');
      		myPlayer.stopVideo();
      		};
      
      		function pausethevideo(){
      		var myPlayer = document.getElementById('my-video'); 
      		myPlayer.pauseVideo();
      		};
      		
      		
      		wrapper.innerHTML='<div> <div> allowfullscreen></div></div>';
      
      		
      
      		
      
      			
      		//wrapper.appendChild(compliment);
      
      		return wrapper;
      	}
      
      });
      

      So with the notificationReceived line, i intend to control my video using the remote control with these codes :

      / edit menu buttons
              "show-all-button": function() {
              var parent = document.getElementById("visible-modules-results");
              var buttons = parent.children;
              for (var i = 0; i < buttons.length; i++) {
               if (buttons[i].id!="module_5_youtube"){
                  if (Remote.hasClass(buttons[i], "external-locked")) {
                      continue;
                  }
                  buttons[i].className = buttons[i].className.replace("toggled-off", "toggled-on");
                  Remote.showModule(buttons[i].id);
                  var notification = "PAUSE_VIDEO";
                  Remote.getWithStatus("action=NOTIFICATION&n"+"otification=" + notification );
                  }
              else{
                      if (Remote.hasClass(buttons[i], "external-locked")) {
                      continue;
                  }
                  buttons[i].className = buttons[i].className.replace("toggled-on", "toggled-off");
                  Remote.hideModule(buttons[i].id);
                              }
      

      Am i doing something wrong here?

      posted in Troubleshooting
      Z
      zichao92
    • RE: Python Shell not working properly on MM

      @Jopyth , the console.log didnt even appear once although the RFID is working. Another issue is that the python script will suddenly stop functioning for no reason and it will start functioning again about 1 minute later ( i realized this when the RFID didnt have any response after i tapped a card. )

      posted in Troubleshooting
      Z
      zichao92
    • RE: Python Shell not working properly on MM

      @Jopyth , im not too sure if i accidentally did it , is there any way to check it?

      posted in Troubleshooting
      Z
      zichao92
    • RE: Python Shell not working properly on MM

      Hi again @Jopyth !
      I hope im not give you a technical nightmare. Here’s the code that i was running on my MM.

      const NodeHelper = require('node_helper');
      const Gpio = require('onoff').Gpio;
      const exec = require('child_process').exec;
      var csv = require('csv-parser');
      var fs = require('fs');
      var PythonShell = require('python-shell');
      var people; 
      
      module.exports = NodeHelper.create({
        start: function () {
          this.started = false;
          this.toggleOn = false;
          
      //exec("sudo python /home/pi/NicoRFID/RFID_playlist.py"); // RFID, hk forced it here.
      
       PythonShell.run('../../../../../home/pi/NicoRFID/RFID_playlist.py', function (err) {
        if (err) throw err;
        console.log('finished');
      }); 
      
      function chaofunction(){
      fs.createReadStream('/home/pi/MagicMirror/rfid_log.csv')
        .pipe(csv())
        .on('data', function (data) {
          console.log('People Left: %s ', data.People_left);
          people = data.People_left;
        });
      }
      
      setInterval(chaofunction,4000);
      

      Notice PythonShell.run('../../../../../home/pi/NicoRFID/RFID_playlist.py', function (err) { if (err) throw err; console.log('finished'); });

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      @Jopyth, I realized i was using an older version of your remote control. However, after updating the remote control module, i inserted your recommended line back into this code:

        // edit menu buttons
              "show-all-button": function() {
              var parent = document.getElementById("visible-modules-results");
              var buttons = parent.children;
              for (var i = 0; i < buttons.length; i++) {
               if (buttons[i].id!="module_5_youtube"){
                  if (Remote.hasClass(buttons[i], "external-locked")) {
                      continue;
                  }
                  buttons[i].className = buttons[i].className.replace("toggled-off", "toggled-on");
                  Remote.showModule(buttons[i].id);
                  var notification = "SCREEN_WAKEUP";
                  Remote.getWithStatus("action=NOTIFICATION&n"+"otification=" + notification );
                  }
              else{
                      if (Remote.hasClass(buttons[i], "external-locked")) {
                      continue;
                  }
                  buttons[i].className = buttons[i].className.replace("toggled-on", "toggled-off");
                  Remote.hideModule(buttons[i].id);
                              }
      

      I was testing this code with paviro’s PIR module ( https://github.com/paviro/MMM-PIR-Sensor) on this line which is found from his MMM-PIR-Sensor.js .

      	notificationReceived: function(notification, payload) {
      		if (notification === "SCREEN_WAKEUP"){
      			this.sendNotification(notification, payload)
      		}
      	},
      

      I modified the PIR code in such a way that when it receives the SCREEN_WAKEUP notification , it will perform certain actions for me rather than turning on the monitor.

      posted in Troubleshooting
      Z
      zichao92
    • Python Shell not working properly on MM

      Hi guys,

      Im not too sure if anybody has this issue with the library var PythonShell = require('python-shell');.

      I wrote a python script that runs a RFID hardware that allows card tapping. Once someone taps the card, a music will play. The script works great on it’s on by using sudo python myscript.py and it’s meant to be passive, meaning that the script will keep running once it’s activated. The music will only play once once it detects the first card and it will not replay it again. However, the problem comes in when I tried to run it via PythonShell on MagicMirror.

      I realized that the script got recalled multiple times while magicmirror is running. I realized this problem when i tap the card again. This results in me hearing echo music.

      Has anyone encountered this issue before?

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      @Jopyth ,

      I tried that method to send a notification to the node_helper.js and from there, to broadcast the notification ‘PAUSE_VIDEO’ via sendNotifcation to another module with notificationReceived code at the receiving end.

      However, I got an error stating that sendNotifcation as error reported as TypeError: this.sendNotification is not a function . Is there any work around to this?

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      Hi @Jopyth ,

      I looked through your code regarding generic notification request under your MMM remote. However, im not too sure how to incorporate the notification request into my modification. I tried replacing this.sendNotification("PAUSE_VIDEO", payload); with ?action=NOTIFICATION¬ification=PAUSE_VIDEO, however it doesnt work.

      Can you assists me regarding this?

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      @Jopyth , yea I’m using and modifying your remote module. Thanks for the tip, will try it out soon

      posted in Troubleshooting
      Z
      zichao92
    • 1 / 1