general purpose timer

otacke's picture
Forums: 

A while ago, I noticed that the memory game uses a timer that is tied to the library closely. It cannot be used for anything else. I decided to create something like a general purpose timer for H5P. And here it is: https://github.com/otacke/h5p-timer. You will also find it attached to this post as an h5p file. It is not a content type, so don't expect it to do anything on its own ;-)

The timer is not intended for time critical applications, but it can easily be used to keep track of time in games, to set a time limit for tasks, or to create other innovative content libraries that need triggers based on time. What about a mod-player that can handle ProTracker files for example? ;-) Also, it might reduce some redundancies across different h5p libraries under the hood.

The timer...

  • can count up and down
  • can use milliseconds internally but only "displays" tenths of seconds and above
  • can be paused
  • keeps track of three different types of counters: clock time (can be modified even if running, e.g to give a time bonus), playing time (the amount of time that the clock has been ticking), and running time (the total running time ignoring pauses)
  • offers three types of notifications using callback functions for each type of counter: notification at a particular point in time, notification after a certain time period has passed, and recurring notifications in fixed intervals
  • offers some static utility functions: check if something is a timecode, convert timecodes to milliseconds and vice versa, extract single time elements like days or seconds from timecode or milliseconds

It may still contain bugs, but I think that someone else should have a closer look at it. I hope that my comments are good enough to help you. Your feedback is highly appreciated!

H5P file: 
icc's picture

Cool, seems like it would cover most of one's needs in a timer. Perhaps Memory Game should start using this soon!

If there's something that could have made it even greater it would be implementing the H5P.EventDispatcher, thus allowing events like start, stop, reset etc.

Great work!

otacke's picture

I'll gladly figure out how the EventDispatcher works and implement it!

otacke's picture

I had a look at the H5P.EventDispatcher. Seems to pretty straight forward. I'll be back home from a business trip to Denmark (where they also just learned about h5p :-D) in about 3.5 hours. Maybe I'll be awake enough to squeeze it in my code today.

otacke's picture

Done. At least basic stuff (play, pause, stop, reset). I'll have another look at the code in order to see if there might be something more I could do - maybe add the counter times as event data or something like that. But not before I've had some sleep. Was a looooong day :-)

thomasmars's picture

Looking good :)

otacke's picture

Thanks! I'll probably write a brief "how to" document resembling your guides, so it becomes easier for people to use it - and especially to hunt bugs.

otacke's picture

I added the Event Dispatcher as already stated above, and I ironed out some flaws. Feel free to check out v0.2-alpha of the H5P-Timer on github or using the file attached to this post. You will also find some documentation about the H5P-Timer functions that you can use in the github wiki.

If you stumble upon anything that in your opinion should be improved, please drop me a note. Especially: What would be left to do so the library might become part of the official H5P releases?

thomasmars's picture

Looks like you have done a very good job, I haven't been able to go through it completely but it looks very comprehensive. Nice!

To become a part of the official H5P release it would have to be used by an official H5P library.

otacke's picture

I knew why I already prepared https://github.com/otacke/h5p-memory-game/tree/H5P-Timer this weekend as a demonstration ;-) Should I just create a pull request for the memory game linking to/mentioning the repository of H5P-Timer?

 

otacke's picture

Create pull request: done.

icc's picture

Thank you! We'll have a look shortly, stay tuned :-)

Has anyone combined this timer to the flashcards? I haven't been able to find anything but I need one. Or if anyone is up for the task? 

This was a great idea...is the one linked the most updated version?  We'd like to use a timer on almost every activity

otacke's picture

Hi Riff!

The one in the repository (https://github.com/otacke/h5p-timer) is the most recent version, yes.

Best,

Oliver

Hi,

I use h5p on matematiktestleri.net. I create math quizzes with "question set". I want to add a timer to the quizzes. How can I do that?

otacke's picture

Hi!

Coding... ;-) Sorry, there's no step-by-step guide that I can give you. The repository is there, you load the timer class in library.json, you get yourself an instance and do what you need (https://github.com/otacke/h5p-timer/wiki/API-documentation).

Best,

Oliver 

Hi, the function for a timer in the presentation is still a coder thing... is there a way to make it understandable for non coders? It is only a timer, a function that exist since 1994 in power point, but a funciton that is really usefull and important for a presentation.
@otacke isn't possible to make your project of 2016 more accessible?

https://www.olivertacke.de/2016/08/15/teaching-h5p-to-present-automatica...

maybe as a part of your fantastic content page?

https://www.olivertacke.de/labs/h5p-content-types/

please
Thanks
Luke

otacke's picture

I am not sure if I understand what you are referring to. A content type that counts up or down or shows the current time? Either way: "I can't do this all on my own, no I am no, I'm no superman ..." (Lazlo Bane)

hi,
thanks for answering
your posti title was "Teaching H5P to present automatically", so my question and proposal is to make available an option for every slide to set a duration time, which would enable the possibility to have automated and also looped timed presentation.

 You wrote on that post" With my contribution you can activate an auto presentation mode that will show each individual slide as long as you want to – or you simply set a global time period like 20 seconds for Pecha Kucha. You can also decide whether you want the presentation to loop indefinitely or not." Where is it then? Well, it’s not totally finished. You can already get it from github and use it, but the presentation editor still lacks the option to set a time period for a slide conveniently. Until now, you will have to edit the H5P file manually if you need individual settings. But, when that is done, you may be able to create something like this… Isn’t that nice?"

so if possible, can you reactivate this project and then add it to your h5p content page?
very much thanks

otacke's picture

Hi!

I see, so you want time-based progression of slides. My old code was lost, but my experience with H5P has increased exponentially compared to then :-D It's not complicated, but I'd still need to find the free time. Same goes for the H5P core team, because they are the maintainers of Course Presentation (and I'll not host a fork on my website) and will have to invest their time (=money) into reviewing, testing and releasing.

Not meant offensive, but most people are always quick to request all kinds of things here on the forum, but hardly wonder how much effort is put into things to fulfill their wishes and solve their problems.

Best,

Oliver