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.

    Timer on Module

    Scheduled Pinned Locked Moved Unsolved Troubleshooting
    22 Posts 4 Posters 5.7k Views 4 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
      dsmtweaker
      last edited by yawns

      I am very new to using Java, as my background is only in VB.

      I am trying to add a timer to a module, in this case the MMM-HTMLVideo module. Basically instead of the video just looping(default) I wanted to make the video play at set intervals, say every 5 minutes, etc.

      I tried adding the following code to the MMM-htmlvideo.js, but nothing loads, nor do I see any errors in nps start dev

      // Override dom generator.
      		getDom: function() {
      				var intervalID = window.setInterval(GetVid, 60000);
      				var video =  document.createElement("video");
      			function GetVid() {
      				video.src = this.config.videoSRC;
      				video.autoplay = true;
      				video.loop = this.config.loop;
      				return GetVid;
      					}
      					}
      
      S ? 4 Replies Last reply Reply Quote 0
      • S Offline
        sdetweil @dsmtweaker
        last edited by

        @dsmtweaker do ctrl-shift-i to open the dev console, and then select the console tab

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • S Offline
          sdetweil @dsmtweaker
          last edited by

          @dsmtweaker it would be setInterval (this.GetVid,…)

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 0
          • S Offline
            sdetweil @dsmtweaker
            last edited by

            @dsmtweaker also think the getVid routine return is wrong

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            1 Reply Last reply Reply Quote 0
            • ? Offline
              A Former User @dsmtweaker
              last edited by A Former User

              @dsmtweaker
              getDom() is not good position for your job. That function will be called at anytime when it is needed to redraw your module by MM, not by you. You don’t know when it will be executed on which condition.

              Instead direct calling getDom, use updateDom(). Whenever you call ‘this.updateDom()’, MM will execute your getDom() and redraw your module with result of getDom()

              Then, with setInterval(), you can repeat updateDom as your wish.

              Of course, setInterval and updateDom should move out of getDom. So to where?

              start() isn’t good also. My suggestion is, to create function yourJob() and put setInterval and uodateDom into yourJob(). Then call it by notification - “DOM_OBJECT_CREATED”.

              D 1 Reply Last reply Reply Quote 0
              • D Offline
                dsmtweaker @Guest
                last edited by yawns

                @sean So, should I be putting the updateDom in a function? Such as…

                // Override dom generator.
                		getDom: function() {
                				var intervalID = window.setInterval(this.GetVid, 60000);
                				var video =  document.createElement("video");
                				video.src = this.config.videoSRC;
                				video.autoplay = true;
                				video.loop = this.config.loop;
                			function GetVid() {
                				updateDom
                					}
                					}
                
                ? 1 Reply Last reply Reply Quote 0
                • ? Offline
                  A Former User @dsmtweaker
                  last edited by A Former User

                  @dsmtweaker
                  I’ve added in prior post. Sorry I’m typing on my phone. So I cannot write long…

                  1 Reply Last reply Reply Quote 0
                  • ? Offline
                    A Former User
                    last edited by A Former User

                    job: function() {
                      setInterval(()=>{
                        this.updateDom() // this will execute your getDom()
                      }, yourInterval)
                    },
                    
                    notificationReceived: function (noti, payload, sender) {
                      if (noti == “DOM_OBJECT_CREATED”) this.job()
                    
                    },
                    
                    getDom: function () {
                      //making  your video DOM here.
                    }
                    
                    D 1 Reply Last reply Reply Quote 0
                    • D Offline
                      dsmtweaker @Guest
                      last edited by

                      @sean Sorry for being so new at this. And thank you for all of the help. I tried using your code.

                      get: function() {
                      setInterval(()=>{this.updateDom()}, 60000)
                      notificationRecieved: function (noti, payload, sender) {
                      if (noti = “DOM_OBJECT_CREATED”) this.job()

                      		},
                      getDom: function ()
                      			var video =  document.createElement("video");
                      			video.src = this.config.videoSRC;
                      			video.autoplay = true;
                      			video.loop = this.config.loop;
                                   },
                      

                      });

                      But I get “Uncaught SyntaxError: Unexpected token (” from notificationRecieved: function (noti, payload, sender) {

                      S 1 Reply Last reply Reply Quote 0
                      • S Offline
                        sdetweil @dsmtweaker
                        last edited by

                        @dsmtweaker you missed some of the job function
                        this.updateDom()

                        }, yourInterval)

                        Sam

                        How to add modules

                        learning how to use browser developers window for css changes

                        D 1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 3
                        • 1 / 3
                        • 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