On Playerstop function & Counter

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
JamesWebster
Posts: 25
Joined: Sun Aug 07, 2011 11:36 am

On Playerstop function & Counter

Post by JamesWebster » Sat Jan 14, 2012 10:52 am

Code: Select all

global Videos #just defining the variables I'm using
global Testphase
global TrialreihenfolgeZeit
global TrialreihenfolgeAuswahl
global Läufer
global Timer
local filepath
local Alt
On Preopencard #just putting things in order, so the user can only see the player
   put 0 into Alt
      put specialFolderPath("desktop") & "/deliberation/" & Videos[Läufer] into filepath
   set the filename of player "Trial.1" of card "Trial1" to empty
   show player "Trial.1" of card "Trial1"
   
   disable button "Kein Foul" of card "Trial1" 
   disable button "Foul" of card "Trial1" 
   disable button "Weiter" of card "Trial1"
end Preopencard

On Opencard #inputting the Video into player and "" into the field, which is supposed to contain the Counter, starting the video
   set the filename of player "Trial.1" of card "Trial1" to (filepath) 
   start player "Trial.1" of card "Trial1"
   put "" into field "Counter.1" of card "Trial1"
end Opencard

On playStopped #supposed to do some things, If Testphase is 1, it's working
   If Alt = 0 then
   set the filename of player "Trial.1" of card "Trial1" to ""
   enable button "Weiter" of card "Trial1"
   enable button "Kein Foul" of card "Trial1" 
   enable button "Foul" of card "Trial1" 
   put the milliseconds into TrialreihenfolgeZeit[Läufer]
   If Testphase = 1 then
      Else
   repeat with x = 0 to Timer
      wait for 1 second with messages
      put Timer-x into field "Counter.1" of card "Trial1"
   end repeat
End if
put 1 into Alt
go to card "Trial2"
End if
end playStopped
On CloseCard
   #answer Läufer
   add 1 to Läufer
end CloseCard
Hi,

I'm curently still working on the Video-Loop thing. It's basically three cards: An Introductionary Text, then on the next card a Video is played. After the Video is played there's supposed to be a Counter which counts from 8 to 0, then it goes to the next card. If the user however selects a Radiobutton before the Counter is done he can select the next button and go to the next card, which shows a the same things as the previous card: Video, Counter, Radio Buttons. After the user or the Counter goes on the next card is the introduction again, then Video1, then Video2 again. This Loop doesn't work with the Counter yet. The Code above works if Testphase =1, which means that it works without the Counter. How can use the Counter correctly?

best regards
James
Attachments
deliberation_ressurection.livecode.zip
(4.69 KiB) Downloaded 248 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: On Playerstop function & Counter

Post by bn » Sat Jan 14, 2012 5:40 pm

Hi Florian/James

I looked at your code and think that your problem might have to do with you trying to go to the next card before the handler has finished. Maybe a send in time is better suited. I tried to implement it into your code, but since I can not test your code it might not work.

Code: Select all

global Videos #just defining the variables I'm using
global Testphase
global TrialreihenfolgeZeit
global TrialreihenfolgeAuswahl
global Laeufer
global Timer
local filepath
local Alt
local sCounter

On Preopencard #just putting things in order, so the user can only see the player
   put 0 into Alt
   put specialFolderPath("desktop") & "/deliberation/" & Videos[Laeufer] into filepath
   set the filename of player "Trial.1" of card "Trial1" to empty
   show player "Trial.1" of card "Trial1"
   
   disable button "Kein Foul" of card "Trial1" 
   disable button "Foul" of card "Trial1" 
   disable button "Weiter" of card "Trial1"
end Preopencard

On Opencard #inputting the Video into player and "" into the field, which is supposed to contain the Counter, starting the video
   set the filename of player "Trial.1" of card "Trial1" to (filepath) 
   start player "Trial.1" of card "Trial1"
   put "" into field "Counter.1" of card "Trial1"
end Opencard

On playStopped #supposed to do some things, If Testphase is 1, it's working
   If Alt = 0 then
      set the filename of player "Trial.1" of card "Trial1" to ""
      enable button "Weiter" of card "Trial1"
      enable button "Kein Foul" of card "Trial1" 
      enable button "Foul" of card "Trial1" 
      put the milliseconds into TrialreihenfolgeZeit[Laeufer]
      If Testphase = 1 then
         --      Else
         --           repeat with x = 0 to Timer
         --                  wait for 1 second with messages
         --                  put Timer-x into field "Counter.1" of card "Trial1"
         --            end repeat
         --      End if
         
         put 1 into Alt
         go to card "Trial2"
      else
         put 0 into sCounter
         send doCounter to me in 0 milliseconds
      end if
   End if
end playStopped

on doCounter
   if sCounter <=  Timer then
      add 1 to sCounter
      put timer - sCounter into field "Counter.1" of card "Trial.1"
      send doCounter to me in 1 second
   else
      -- sCounter > Timer exit send doCounter since
      -- Countdown finished on its own
      put 1 into Alt
      go to card "Trial2"
   end if
end doCounter

On CloseCard
   #answer Laeufer
   add 1 to Laeufer
   
   -- sCounter did not count down all the way 
   -- user pressed button go next
   if sCounter <= Timer then
      cancelDoCounter
      put 1 into Alt
   end if
end CloseCard

on cancelDoCounter
     -- cancel all calls to doCounter
      repeat for each line aLIne in the pendingMessages
         if aLine contains "doCounter" then
            cancel item 1 of aLine
         end if
      end repeat
end cancelDoCounter
you probably should add cancelDoCounter to the button "Weiter" like this:

Code: Select all

global Läufer
global Videos
global TrialreihenfolgeZeit
on mouseUp
   cancelDoCounter
   put (the milliseconds - TrialreihenfolgeZeit[Läufer]) into TrialreihenfolgeZeit[Läufer]
   answer TrialreihenfolgeZeit[Läufer]
   If Läufer = 3 then
      answer Videos[1] & ":" & TrialreihenfolgeZeit[1] & ";" & Videos[2] & ":" & TrialreihenfolgeZeit[2] & Videos[3] & ":" & TrialreihenfolgeZeit[3] with "ok"
   End if
   add 1 to Läufer
   unhilite button "Foul" of card "Trial1" 
   unhilite button "Kein Foul" of card "Trial1" 
   go to card "Trial2" of stack "deliberation_ressurection"
end mouseUp
I tried a little mind reading since I don't really know what you are up to.

It would help if you made a stack that isolates the problem with maybe 2 cards and the option to choose a movie file for test1 and test2. Add the count down. See if the script fails and then post just that small stack that everyone can try it without too much guess work. It would really make it easier helping you.

Kind regards

Bernd

PS what is currently your first name: Florian or James? :)

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: On Playerstop function & Counter

Post by bn » Sat Jan 14, 2012 10:45 pm

Hi Florian-James,

I made a little stack with 3 of your cards: test1, test2 and Intro

I changed the code somewhere along the lines of what I posted above. I include a short movie for testing. It is in 3gp format and should run on a Mac. If it does not work just put another movie into the same folder as the stack is and change the code in preopencard of test1 and test2.
Note my spelling of resurrection.
deliberation.zip
(68.66 KiB) Downloaded 238 times
Kind regards

Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: On Playerstop function & Counter

Post by bn » Sun Jan 15, 2012 1:27 am

Hi James,

one thing I noticed is that the counter in my stack was not working quite right. The reason is that the playStopped message is send
A when the movie stops
B when the filename of the movie is set changed

From the dictionary:
Note: The playStopped message is sent when a card containing the player closes and when the player's filename property is changed. If the player is hidden, or the movie or sound is not currently running, the message will still be sent. To prevent a playStopped handler from being executed inappropriately, set the lockMessages to true before changing the filename or switching cards:

lock messages -- prevent sending playStopped
set the filename of me to newFile
unlock messages
I did not know that. In your playStopped handler you set the filename of the player to empty. This triggers a second playStopped message, effectively repeating the playStopped handler.

In the stack I posted if you lock / unlock the messages around setting the filename of the player to empty then the counter works correctly. Like this

Code: Select all

 lock messages
 set the filename of player "Trial.2" of card "Trial2" to ""
 unlock messages
of course you would also have to change that on card "Trial1".

Once the filename of the player is set to empty then leaving the card does not trigger playStopped.

Learned something new.

Kind regards

Bernd

JamesWebster
Posts: 25
Joined: Sun Aug 07, 2011 11:36 am

Re: On Playerstop function & Counter

Post by JamesWebster » Sun Jan 15, 2012 3:02 pm

Hi Bernd,

thank you very much for your help, it's working perfectely! :)
It would help if you made a stack that isolates the problem with maybe 2 cards and the option to choose a movie file for test1 and test2. Add the count down. See if the script fails and then post just that small stack that everyone can try it without too much guess work. It would really make it easier helping you.
:oops: I'm going to do that next time!
Note my spelling of resurrection.
Spelling never was my strong point :D
PS what is currently your first name: Florian or James? :)
It's a double name, the name ordinarely used depends on which part of my family is talking to me^^

best regards
James

Post Reply