Announcement

Collapse
No announcement yet.

How to activate a new form and play video with one action?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to activate a new form and play video with one action?

    When I press a button on Fom1, I would like it to activate Form2 and play a video in Form2. I have linked the button's OnChanged event to Form2Activate. But Form2's OnActivate event can't be linked to Timer0play (to start the video).

    If I have to use MagicEvent, invoked by the button, how do I start the timer in the code? I can activate the form using ActivateForm.




  • #2
    Hello Johnsont,

    It seems that you are at the right path.

    Absolutely, you can use the MagicEvent (invoked by a button). All you have to do is add the MagicEvent object. It will be placed on Form0 by default. Don't worry as this will work even if your button is on Form1. Next, link the button's Onchanged event to the MagicEvent. Afterwards just go to the MagicEvent object then click the ellipses symbol and add the code as shown below.

    Note: Please add the Timer object first.

    Code:
    func MagicEvent0(var newval)
    ActivateForm(1);
    sys_SetTimer(TIMER0,10); // where 10 is the frame delay
    endfunc
    After that, link the Timer's OnTimer event to Video0NextFrame.
    Note: The interval of the timer should be equal to the frame delay of the video. I've attached a sample program to further demonstrate my point.

    If you are not aware about Genie Magic Callable Functions please do the following:
    1. Run Workshop4
    2. Select "New" then choose your display, after that choose "Visi-Genie Environment"
    3. Just pressed F1, then navigate to section "6.1. Genie Magic Callable Functions" (page 42).

    I would suggest visiting the application note for Visi-Genie Play Video: https://www.4dsystems.com.au/downloa...0007_R_1_0.pdf

    Hope this will help you.

    Best Regards,

    Kayven
    Attached Files
    Last edited by michael_4D; 11 May 2018, 08:52 PM.

    Comment


    • #3
      Thanks for the information.

      Does sys_SetTimer turn on the timer to run once or indefinitely? If it only runs once and so only causes 1 frame change, I'd need a for loop to go through all frames.
      But if it runs indefinitely, will it stop at the last frame or will it cycle to the first frame? How do I stop the timer?

      I've looked up the application note earlier and it uses Timer0Play and Timer0Stop. I can't work out the equivalent in-the-code functions.


      Comment


      • #4
        I just implemented the recommended code and could confirm that the timer caused the video to run up to the last frame.

        Is it possible to automatically jump to another form at the end of the video? The video object only has 1 event: OnChanged. The list of available handlers does not include form activation.

        I attempted to link the OnChanged event to a MagicEvent. But the MagicEvent was not triggered.

        Comment


        • #5
          Hello Johnsont,
          Recently, I gave you an example on how to activate a new form and play the video with one action but it seems different from what you intend to do so we have to start with a different method.

          Inside the MagicEvent() function, sys_SetTimer() initializes TIMER0 to a value. TIMER0 then decrements from the initial value down to 0. As soon as the value reaches 0, the next frame of the video is shown. This occurs repeatedly until the program reaches the last frame of the video.

          For the question on how to stop the timer, you can write:
          Code:
          sys_SetTimer(TIMER0,0);
          I suggest that you use MagicCode objects because you want to go through all frames by using a for loop, am I correct?
          And also please be aware about insertion point that is introduced by the MagicCode objects.

          Click image for larger version

Name:	insertion note.jpg
Views:	230
Size:	19.7 KB
ID:	63540

          If you are not aware about MagicCode objects, try to visit the application note:

          https://www.4dsystems.com.au/appnote/4D-AN-00199/
          http://www.4dsystems.com.au/download...0199_R_1_0.pdf

          So, I have attached a sample project that is related to your concern. It is a good start for implementing MagicCode objects under the ViSi-Genie environment. The sample project consists of two forms, two winbuttons and a video.

          At the beginning, the program was initially on Form0 then the video frame started to increment until it reached the last frame. After that, it navigated to Form1.

          Hopefully this will help you.
          Best Regards,

          Kayven

          Comment


          • #6
            Thanks Kayven for the information.

            I actually want the form to jump to another jump immediately after the video ends, without having the user to press a button.

            I envisage that I need to check for the video frame index in a while loop in the MagicEvent function.

            Code:
            get the current frame index using get_Word
            while (frame index is not the last)
                get the current frame index using get_Word
            endwhile
            ActivateForm(nextForm);

            Comment


            • #7
              Hello Johnsont,

              From your post, I think you want to use a while() loop inside the MagicEvent object for checking and changing the video frame, am I correct? Unfortunately, this will generate a problem.

              It is not advisable to use a while loop or a for loop inside the MagicEvent object, because it will block the changing of the video frame and other ViSi-Genie background tasks. Also, remember that in your case MagicEvent object runs once only.

              The only solution is by using a MagicCode object and by changing its insertion point to “mainloop” (very important). This will help you achieve real-time frame checking, changing of video frames and execution of other actions without blocking ViSi-Genie background tasks.

              I’ve attached a sample project to demonstrate my point.

              Note: I’ve used Timer0 object and its OnTimer event is linked to Video0NextFrame.

              Hopefully, this will help you.

              Best Regards
              Kayven
              Attached Files

              Comment


              • #8
                No, I want the form to jump to another jump immediately after the video ends, without having the user to press a button.

                Here is the sequence.
                1. Form0 opens
                2. Video0 starts
                3. Video0 finishes
                4. Form1 opens
                At the end of Video0, Form1 should open automatically. The examples I have seen so far involves pressing a button to move from Form0 to Form1.

                Is it possible to open Form1 immediately after the video finishes?

                Comment


                • #9
                  Hi Johnsont,

                  Sorry if I forgot to mention that you can also modify the second attached sample project then remove the buttons. It will then work exactly as you described.

                  I’ve attached a modified version of the sample project.

                  Hopefully, this will help you.

                  Best Regards,
                  Kayven
                  Attached Files

                  Comment


                  • #10
                    Thanks! I understand the code.

                    If I want to have another action (e.g. changing PWM values) which might be running at multiples of the frame interval, should I use another timer and code it in the same timer handle function?

                    Would the 2 timers become out-of-sync significantly?

                    Comment


                    • #11
                      Hi Johnsont,

                      That’s possible. You may use a separate timer and a separate timer event function. Attached is an example of this application. (Sample1.zip)

                      Alternatively, you may also count how many times the timer event function executed. For example, every fifth time the frame was updated through the event function, we can print a message.

                      Here’s another example using this alternative method. (Sample2.zip)

                      Hopefully, this will help you.

                      Best Regards,
                      Kayven
                      Attached Files

                      Comment


                      • #12
                        Hi,

                        I am working on ViSi Genie with an Arduino Leonardo as host. It is playing a Video at the start of the screen using Video and Timer, at that point everything is ok. I need to restart the video from the arduino... Someone knows how to get that?

                        Regards,

                        Sebastian.

                        Comment


                        • #13
                          Hello Sebastian,

                          You could try to put a read object on your main loop for your video object and then on your event handler function, you could check for the current frame of your video object.

                          Everytime your video reaches its final frame, you could Write it back to frame zero.

                          I hope this helps.

                          Best regards,
                          Michael

                          Comment


                          • #14
                            Hello Michael,

                            Could you please give me the exact line for write back it to zero from arduino? I'm using this "genie.WriteObject(0X14, 0, 0);" but it does not work.

                            Regards,

                            Sebastian

                            Comment

                            Working...
                            X