A while ago, I noticed that the memory game of H5P 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! You can check it out it on github.
What is it good for?
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.
What can the H5P-Timer actually do?
First of all, the H5P-Timer can can count up and down. Wow, right? :-) Additionally, it can be paused. Really! More interestingly, it 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 when not paused)
- running time (the total running time ignoring pauses)
I am not sure if there’s a use proper use case for all of them, but maybe you have something in mind?! Furthermore, the timer offers three types of notifications using callback functions. All three counter types can be used as a trigger. You can set up:
- a notification at a particular point in time,
- a notification after a certain time period has passed, and
- recurring notifications in fixed intervals.
For example, you could set up a two minute warning for a countdown with a notification at a particular point in time. Or you could remove special powers that were granted a game character after 30 seconds have passed. Or you might just add a ticking noise to a clock every single second. It’s up to you! Apropos clock: the timer can use milliseconds internally but only „displays“ tenths of seconds and above. Everything else wouldn’t make too much sense, I guess.
Hmm, what else can the timer do? It will dispatch events for play, pause, stop and reset. You might want to listen for them.
Finally, the timer offers some static utility functions. You can
- 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.
Help, I need sombody, help!
I think that someone else should have a closer look at the H5P-Timer because it may still contain some bugs. While I have not completed my documentation, I hope that my comments are good enough to guide you. Your feedback is highly appreciated! Also, please let my know in the comments what content libraries you can imagine to use the H5P-Timer for!