Set objects visible after 'X' seconds while player's playing

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
rafakol
Posts: 5
Joined: Thu May 20, 2010 5:46 pm

Set objects visible after 'X' seconds while player's playing

Post by rafakol » Thu May 20, 2010 6:00 pm

Hello guys,

I'm new on this and I'm making my first 'not-easy' application so before of all thank you everyone in this community.

What I want to do is to easy to explain. I push a button so a new card with a player and some buttons appears. The player starts but the buttons are no-visible. So after 'x1' seconds button1 is set to visible, after x2 seconds button is set to visible... and so on.

I've been reading and I know it can be made with callbacks, but I don't know how to use them neihter where to place them. Any help please??????

Thank you all!
Rafa

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

Re: Set objects visible after 'X' seconds while player's playing

Post by bn » Thu May 20, 2010 7:04 pm

Hello Rafa,

welcome to the forum.
this is a link to an article in the RunRev Newsletter. It explains callbacks.
http://www.runrev.com/newsletter/july/i ... tter3.html

and I attach a stack by Klaus Major, which he posted on the old RevOnline, not easily accessible with Rev 3.5 and beyond.
I hope Klaus does not mind.
It is a very nice example stack to demonstrate callbacks.

Basically what it amounts to is that you can set a property of a player with a list of callbacks. One callback per line.
For the timing of the callbacks you will want to know how to when the callback is made.
For this you have to realize that a movie/audio in a player has a time scale. That time scale slices the seconds into individual intervals.
As an example: You have a movie of 5 seconds. The movie has a timescale of 600. So every second has 600 "time slices" and since the movie is 5 seconds long you get 3000 "slices". This is the duration of a movie. (by the way 600 is often used in movies, but not always). If you want a callback after 1 second you say
600,showbutton
after 2 seconds
1200, showButton
When the movie/audio is playing and reaches these time slices, which by the way is the currentTime of a player, it fires off the callback to the player object.
You have to provide a handler to take care of the "showButton" part of the callback.

I made a simple player with a movie of a duration of 720. The timescale is 600.
to find out the above I made a button

Code: Select all

on mouseUp
   put the duration of player 1 && the timescale of player 1
end mouseUp
which puts the duration and the timescale into the message box.
In another button I placed this:

Code: Select all

on mouseUp
   put "300,showButton 1" & return & "600,showButton 2" into aList
   set the callbacks of player 1 to aList
end mouseUp
You will notice that I put "showButton 1" as the callback. This way the callback showButton will also send a parameter,in this case 1. I use this to address the buttons later.
in the script of the player I put this script:

Code: Select all

on showButton whichButton
   put "b" & whichButton into tButtonName
   set the visible of button tButtonName to not the visible of button tButtonName
end showButton


and I made 2 buttons which I named b1 and b2. If you dont want to show the silly name "b1" of a button you can set its label to something more meaningful.
This will toggle the visibility of the buttons after half a second for btn b1 and one second for button b2.
I hope this explains it a bit.
regards
Bernd



If you still have questions dont hesitate to ask.

regards
Bernd
Attachments
the callbacks.rev.zip
(2.93 KiB) Downloaded 330 times

rafakol
Posts: 5
Joined: Thu May 20, 2010 5:46 pm

Re: Set objects visible after 'X' seconds while player's playing

Post by rafakol » Thu May 20, 2010 10:34 pm

Hello Bernd,

And very thank you! It is a really good explication!!!! I understood everything about the timescale, duration and callbacks!!

Anyway I still having problems, I think I'm doing it right but I guess not becuse it doesn't work, so....

The code I wrote into my card is as follow:

Code: Select all

on opencard
   start player 1
   set the visible of button "buttonB" to "false"
   set the visible of button "buttonB" to "false"
    --timescale = 2997 = 1 second
   set the callbacks of player 1 to "2997, ShowButton 1"
   set the callbacks of player 1 to "5994, ShowButton 2"
end opencard

on ShowButton numberOfButton
      set the visible of button numberOfButton to "true"
end ShowButton
But it doesn't work, do you know what I am doing wrong??

Thanks again for your quick answer

Rafa

rafakol
Posts: 5
Joined: Thu May 20, 2010 5:46 pm

Re: Set objects visible after 'X' seconds while player's playing

Post by rafakol » Thu May 20, 2010 11:16 pm

Hello again,

I've found the solution so I answerd to myself and to users with the same problem.

The problem I have it was I didn't put the code of the functions (or messages) in the player. So the messages you want to make after X seconds go to the player script, and the callbacks in the opencard or a button.

My code finally goes like that:
In the player script:

Code: Select all

on showButtonA
   set the visible of button "ButtonA" to "true"
end showButtonA

on showButtonB
   set the visible of button "ButtonB" to "true"
end showButtonB

on showButtonC
   set the visible of button "ButtonC" to "true"
end showButtonC
In the card script:

Code: Select all

 
on opencard
   set the visible of button "ButtonA" to "false"
   set the visible of button "ButtonB" to "false"
   set the visible of button "ButtonC" to "false"
   --timescale = 2997 = 1 second
   put "3000,showButtonA" & return & "6000,showButtonB" & return & "9000,showButtonC" into aList
   set the callbacks of player 1 to aList
   start player 1
end opencard
Another question I want to ask is about to make this list of buttons visible=false easier because is going to be 28 buttons so I'm pretty sure I set them all false in just 1 or 2 lines. Also how to make only just function with parameter to set the buttons visibles.

Regards
Rafa

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

Re: Set objects visible after 'X' seconds while player's playing

Post by bn » Thu May 20, 2010 11:51 pm

Hi Rafa,
glad you got it working.

If you want to make your life easier with hiding the buttons and building the list of callbacks then I suggest you give them a name and a number the way I did in my example. b1, b2, etc

Than you can say

Code: Select all

on opencard
   put empty into tcallbackList
   lock screen
   repeat with i = 1 to 28
      set the visible of button ("b" & i) to false -- brackets are important here for Rev to evaluate "b" & i 
      put 3000 * i & "," & "showButton" && i & return  after tcallbackList
   end repeat
   unlock screen
   delete last char of tcallbackList -- a return character
   set the callbacks of player 1 to tcallbackList
   start player 1
end opencard
at the same time you can make it easier with your callbacks, the same as in the example above in the player script

Code: Select all

on showButton whichButton
   put "b" & whichButton into tButtonName
   set the visible of button tButtonName true
end showButton
It is easier to do this with numbers, if you would want to do it with letters you would have to provide a list of letters first but with 28 buttons or more you would run into problems with the alphabet :)
I did not test for the duration of the player whether it is long enough to support 28 * 3000, you would have to make shure it does.
This is just one way to construct a list with a repeat loop and in this case hide the buttons at the same time. But I think you can see what I am trying to do.

regards
Bernd

rafakol
Posts: 5
Joined: Thu May 20, 2010 5:46 pm

Re: Set objects visible after 'X' seconds while player's playing

Post by rafakol » Fri May 21, 2010 5:47 pm

Yes Bernd...

I'm getting it but slowy but hopefully I start working better with it but simply things are so complicated because in java or c are more difficult, for example I've been more then an hour trying to change the value of a global..... but anyway...

I've done all of this and now my apllycation works how I wanted, but I just want to change a bit because I have 28 cards(one for letter of the alphabet + 2 of control) and those 26 cards actually could be just one changing the value of the video of the player I want to play.

So what I want to do is depending of the button I push, it goes to a card and plays the video, for example i push the button A it goes the video A in a player of card VIDEOS, then when it finish goes automatically to the card HOME.

What I tried is in the button A:

Code: Select all

on mouseUp
   global nameVideo
   set nameVideo to "A.mov"
   go to card Videos
end mouseUp
Then in card Videos:

Code: Select all

on opencard
   global nameVideo
   set the filename of player 1 to nameVideo
   start player 1
end opencard
It could be so silly because i guess it's so simple but it is my first week with this so... i don't know.. xD

Thank u in advance, i keep trying!!!

Rafa

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Set objects visible after 'X' seconds while player's playing

Post by Klaus » Fri May 21, 2010 5:58 pm

Hi Rafa,

you could trap the "playstopped" message!
This message is sent to the player (and card, if not handled in player!) when the playback stops, be it from user action or when the video reached its end!

See the docs (Rev Dictionary) for more info.


Best from germany

Klaus

rafakol
Posts: 5
Joined: Thu May 20, 2010 5:46 pm

Re: Set objects visible after 'X' seconds while player's playing

Post by rafakol » Fri May 21, 2010 6:39 pm

Hi Bernd,

Sorry for keep your time, the playstopped message is awesome, wow!!! now I can make all I wanted without thousands of functions and callbacks!!!!

What I can't do is to choose the video from other card. I explain it. I got 2 cards, HOME and VIDEOS, in HOME I've got 26 buttons so when I push- for example- the button F it goes to card VIDEOS and set the source to "videoF.mov" and then start it. I try with global as I said but still doesn't work, what can I do for it??

Then when it finish it goes to card HOME again- with the playstopped message it save me a huge amount of time ;)!!

Danke Bernd, deine hilfen ist sehr gut!!!!
Rafa!!!

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

Re: Set objects visible after 'X' seconds while player's playing

Post by bn » Fri May 21, 2010 10:33 pm

Hi Rafa,

what you are probably looking for is the filename of the player.

Code: Select all

set the filename of player "x" of card "y" to "a/full/path/to/a/video/file"
you could do this: get a list of all the video files in your video folder then you can set the filename of the player to the full path of the video you want.
To get the folder you could make a button with the following script:

Code: Select all

   answer folder "please choose folder"
   put it
this puts the path to the selected folder into the message box.

I just made a littel stack (attached below) with comments of one way how to do this with fields. You can adapt this to globals or whatever.
That is easier then to describe the steps.
You might want to look up: filename, defaultFolder, the files, repeat for each [element] [name of element] in
  • regards
    Bernd
Attachments
videoFiles.rev.zip
(1.83 KiB) Downloaded 298 times

Post Reply