Skip to first unread message

osama sayar

unread,
Mar 25, 2017, 12:51:51 AM3/25/17
to MIT App Inventor Forum

Hello,

Is there an example for count-up Timer instead of countdown Timer.  

SteveJG

unread,
Mar 25, 2017, 10:36:00 AM3/25/17
to MIT App Inventor Forum
As Taifun said in your previous question, a count up Timer is almost identical to a count down timer.  Instead of counting down from a positive number and subtracting one each second you start counting from 0 and add one.

You should take your existing code for countdown and make a few small changes.


 Isn't it time that you read the Inventor's Guide here http://www.appinventor.org/book2  and reproduce the example code  and start doing some tutorials?  Learning to program is a matter of doing a little reading then experimenting, changing things and seeing what happens.   If you save a copy of your Project with a different name or save an aia of the working code you can not break anything.  

Something like the code below should work.   It is simpler than the code shown at puravidaapps, all it does is count UP.    You need a Button, a Label and a Clock with the interval set to 1000 ms (1 second).

With a small modification, the example code can also count down.    There is no alarm, no code to prevent the app from going to sleep, just the basics.

Regards,
Steve

osama sayar

unread,
Mar 25, 2017, 2:42:50 PM3/25/17
to MIT App Inventor Forum
I need an count-up timer which be able to use a slider and a player with it and make that timer start from any position. 

Ghica

unread,
Mar 25, 2017, 4:37:31 PM3/25/17
to MIT App Inventor Forum
If a count up timer means that I want to know what the date and time is after so many milliseconds from now, then this is not an easy question. Like, tonight at 02:00 a.m. summer time will start here, so 7 hours from now, (21:35) is not 04:35 but 05:35 a.m.
See also this thread: https://groups.google.com/forum/#!msg/mitappinventortest/Z6ATYVSFaEA/0REDZ-5nHAAJ
Cheers, Ghica.

osama sayar

unread,
Mar 26, 2017, 2:54:01 AM3/26/17
to MIT App Inventor Forum
Hi Ghica,
Is it possible to make it only for HH:MM:SS?
Please check the blocks
Thank you
timedifferent.png
timerdifferent2.png

Ghica

unread,
Mar 26, 2017, 5:59:29 AM3/26/17
to MIT App Inventor Forum
Probably yes.
But what is the purpose of this calculation? What do you want to do with it?
Did you test your blocks? What was the result? If it was what you expect, fine. If not, what was wrong?

I am not here as a teacher, checking assignments. My goal is to help people to find answers themselves, which is much more gratifying for both of us.
Cheers, Ghica.


osama sayar

unread,
Mar 26, 2017, 7:27:31 AM3/26/17
to MIT App Inventor Forum
It works but it gives result very slowly. I made it just for getting more experience. 

I need an count-up timer which be able to use a slider and a player of Mp3 with it and make that timer start from any position.

Ghica

unread,
Mar 26, 2017, 5:32:23 PM3/26/17
to MIT App Inventor Forum

osama sayar

unread,
Mar 27, 2017, 12:37:14 AM3/27/17
to MIT App Inventor Forum
There is no problem with that way. But I want to make it with reverse way.

Ghica

unread,
Apr 26, 2017, 10:23:43 AM4/26/17
to MIT App Inventor Forum
You Did not answer my questions, therefore I am not able to answer yours.
Cheers, Ghica

osama sayar

unread,
Apr 26, 2017, 10:59:36 AM4/26/17
to MIT App Inventor Forum
Hi Ghica,
Actually, I need to make it count-up instead of count-down because I want to start clock with Mp3 sound and all of people want to know in which time they are for example they want to 2 minutes back to listen again what is said.

zac

unread,
Apr 26, 2017, 12:11:20 PM4/26/17
to mitappinv...@googlegroups.com
Here is a useful extension to your purpose. 
https://puravidaapps.com/player.php

You may want to use "CurrentPosition", "Duration" and "StartAtPosition".

osama sayar

unread,
Apr 26, 2017, 12:23:27 PM4/26/17
to MIT App Inventor Forum
Thank you so much.
This way is not the thing I want.  I want to know how to build count - up clock.

zac

unread,
Apr 26, 2017, 12:42:42 PM4/26/17
to mitappinv...@googlegroups.com


Have you tried this? It is doing exactly what you have asked.





osama sayar

unread,
Apr 26, 2017, 1:21:27 PM4/26/17
to MIT App Inventor Forum
No, I didn't try it. Can you please send the aia. please if it is allowed.
Thank you.

Ghica

unread,
Apr 26, 2017, 4:47:44 PM4/26/17
to MIT App Inventor Forum
@zac It is really admirable that you come up with code examples as answers to problems, but the problem with software development is not only how to code something but also what. And that is not clear at all in this case. Therefore you do not know which problem your code is solving, certainly not if it is solving osama's problem.

@osama
My definitition of count down is that you want to calculate the time between now and some time in the future, for example how much time is left befor the new year starts. Apparently that is not what you want.
A definition of count-up could be that you want to know what the date-hour-minutes-seconds is after a fixed duration from now. This is a difficult problem to solve in general, but App Inventor has easy blocks to do that: call Clock1 Add duration, for example. But I am pretty sure that this is not what you want either.

What it is -maybe- that you want, is when someone is listening to an .mp3, that he/she can see how much time has passed since he/she started playing the .mp3.
If yes, then you can calculate this the same way as a count-up, you just use the call Clock1.Duration (start, end) block.

So, please show a design of what you want. Try some blocks also to solve your problem and then describe exactly what happens differently from what you think it should be. If tyou do not do that, we will keep shooting in the dark, while you will never be able to learn something and solve your own problems.
Cheers, Ghica.
 

أسامة سيار

unread,
Apr 26, 2017, 5:30:05 PM4/26/17
to MIT App Inventor Forum
Hello Ghica.
Yes what I want exactly, is when someone is listening to an .mp3, that he/she can see how much time has passed since he/she started playing the .mp3. But how can I do that. IT IS REALLY DEFFICULT FOR ME TO DO THAT:)

Ghica

unread,
Apr 26, 2017, 5:45:28 PM4/26/17
to MIT App Inventor Forum
Post a simple aia, then I can add this number (or maybe Zac). Have patience, it is national holiday here tomorrow and it is too late now.
Cheers, Ghica.

zac

unread,
Apr 26, 2017, 8:18:26 PM4/26/17
to MIT App Inventor Forum
@Ghica Thank you for the feedback. I put the example from what I understood form @osama. 

@osama I'm not good at explain in words so look at my attachments and see if that similar to what you want. If so, let me know and I'll try to explain the logic of my blocks.


Capture.PNG
Capture2.PNG
Example.aia

osama sayar

unread,
Apr 27, 2017, 4:03:46 AM4/27/17
to MIT App Inventor Forum
Thank you so much Ghica and Zac. This is exactly what I am looking for. Also I had have two slides. But now, One slide is more enough.
You are a very professional Programmer in Android application. Now, I need  only to add an hour. Is it possible? Because the sound is more than two hours.

Thank you Ghica and Zac

Ghica

unread,
Apr 27, 2017, 7:29:04 AM4/27/17
to MIT App Inventor Forum
Unfortunately this does not work right. You really need two sliders and also you should not use Pause, because of a bug in app inventor.
Read again your other thread: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/mitappinventortest/9UQ2QLO2c9E/G26eF2oYGQAJ
Cheers, Ghica.

Taifun

unread,
Apr 27, 2017, 8:51:44 AM4/27/17
to MIT App Inventor Forum
@Ghica: the pause issue in the Player extension has been fixed meanwhile, see also https://puravidaapps.com/player.php

Taifun

osama sayar

unread,
Apr 27, 2017, 10:00:42 AM4/27/17
to MIT App Inventor Forum
Yes you are right Ghica I have problem after I click pause I can't move the slide but before yes. However, it doesn't matter  because after click pause and then play it continue from the same position. The main problem Now is, I need  only to add an hour. Is it possible? Because the sound Mp3 has  more than two hours. Please help me.

Ghica

unread,
Apr 27, 2017, 11:15:20 AM4/27/17
to MIT App Inventor Forum
@Taifun: Thanks! good to know!

@Osama: To fix the pause bug, download the Player extension again. Load it using a new name. Then, change all the references to the old Player extions to the new Player extension. Finally remove the old player extension.
To add the hour: change the pattern to "hh:mm:ss" (it occurs twice).
Cheers, Ghica.

Taifun

unread,
Apr 27, 2017, 11:22:35 AM4/27/17
to MIT App Inventor Forum
@Ghica: to upgrade an extension, simply import the new version and it will upgrade automatically... it's that simple...
Taifun

Ghica

unread,
Apr 27, 2017, 11:33:17 AM4/27/17
to MIT App Inventor Forum
@Taifun Oh! I did not know that. I thought that it was still the show stopper for releasing new extensions from MIT itself. Thanks!
Cheers, Ghica.

osama sayar

unread,
Apr 27, 2017, 11:33:38 AM4/27/17
to MIT App Inventor Forum
I have already added hh:mm:ss but it seems that show 3;00;00 when start playing and after completing one hour it change to 4:00:00 it means that add one hour to the three.

Ghica

unread,
Apr 27, 2017, 11:42:38 AM4/27/17
to MIT App Inventor Forum
You must have done something else wrong. Cheers, Ghica.

osama sayar

unread,
Apr 27, 2017, 11:53:28 AM4/27/17
to MIT App Inventor Forum
Please see attached.
Thx
add_hour.jpg

Ghica

unread,
Apr 27, 2017, 12:00:25 PM4/27/17
to MIT App Inventor Forum
The problem must be in the part you are not showing. If your time starts with 3:00:00, then the initial calculation must be wrong.
Cheers, Ghica.

osama sayar

unread,
Apr 27, 2017, 12:12:48 PM4/27/17
to MIT App Inventor Forum
I am sorry Ghica.
What can I do to fix the problem.

Ghica

unread,
Apr 27, 2017, 12:16:29 PM4/27/17
to MIT App Inventor Forum
Post an .aia
Cheers, Ghica

osama sayar

unread,
Apr 27, 2017, 12:25:37 PM4/27/17
to MIT App Inventor Forum
Please see attached aia.
Thank you so much Ghica for your usual kindness and help.
I have tested the extension and it works brightly.
Thank you a lot Taifun and Ghica
Example.aia

Ghica

unread,
Apr 27, 2017, 3:21:21 PM4/27/17
to MIT App Inventor Forum




The problem with the hours is this: the duration is formatted as a date-time starting at Januari 1st 1970, taking into account the timezone you are in.
This means, if you are looking at minutes and seconds only, you will not see it, but in my timezone duration 0 is formatted as 01:00:00 and in yours 03:00:00
It is not easily solved by adjusting the timezone, therefore I made a procedure for you to solve it. Look at the blocks attached. For your convenience there is also an .aia
(I did not have the patience to wait for an hour, but I am pretty sure it works).
Cheers, Ghica.
Example_1 (1).aia

osama sayar

unread,
Apr 27, 2017, 3:48:20 PM4/27/17
to MIT App Inventor Forum
Hi Ghica, 
Actually, I am sorry to tell you that I have tested the aia you had sent it many times waiting hour to come but it hasn't come at all.

Ghica

unread,
Apr 27, 2017, 6:30:35 PM4/27/17
to MIT App Inventor Forum

It seems I left some test values in. Now a made a proper calculation, not using the clock. Getting tired I suppose.
Cheers, Ghica
Example_1 (2).aia

osama sayar

unread,
Apr 27, 2017, 7:44:13 PM4/27/17
to MIT App Inventor Forum
Now I can sleep in a very deep after you have solve my problem.
Good luck Ghica!
Thank you so much for all you have done to let my app succeed.

Ghica

unread,
Apr 28, 2017, 1:35:11 AM4/28/17
to MIT App Inventor Forum
You may want to add a leading zero sometimes, to make sure you always see 2 digits for the hours, mins, secs, like 01:08:05 etc. You should be able to find a procedure for it in the forum, otherwise I will add it tonight.
Cheers, Ghica

Ghica

unread,
Apr 28, 2017, 11:33:47 AM4/28/17
to MIT App Inventor Forum
Next time I do not reply when you write to me privately.
You wrote:
I want to add the fixed total amount hours, mins, secs like 01:08:05 at the end of slider.

I added it to the .aia attached. I think you could have done it yourself easily.
I also added a procedure to make sure you always have two digits for values, adding a leading zero if needed.
Cheers, Ghica.



Example_1 (3).aia

osama sayar

unread,
Apr 28, 2017, 2:49:13 PM4/28/17
to MIT App Inventor Forum
Hi Ghica,
I am so sorry to send you in private.
Sure, I didn't tend to send it in private. In fact, by mistake I have opened my email instead of opening forum page:)
I am so happy to help me.
I have tested it and it is ok now.
Thank you so much!

Reply all
Reply to author
Forward
0 new messages