When you're feeling down and lonely
About
I don't know why, but my girlfriend bursts out laughing violently when she sees or hears someone making strange sounds with their mouths or getting flustered. Needless to say, there are parts of certain movies that make her literally go crazy.
I therefore got the idea, for our thirteenth anniversary, to give her a system that would allow her to laugh indefinitely whenever she feels down or lonely.
I used a couple of movie clips that make her laugh every time and I looped the movies with the ability to play specific parts of the looped footage by simply pressing the keys on the keyboard.
We found the result hilarious, my children have played with it for hours laughing like crazy.
Technically
The basic idea is simple: stack youtube videos on top of each other and start one or the other video in time by specifying the times accurately. In the meantime, show or hide the videos so that the user experience is fluid and the presence of Youtube transparent.
The most complicated part is represented by the interaction with the youtube api and the management of the loading of the videos so that the user experience is smooth and uninterrupted.
To simplify and accelerate the development I made the definition of the videos involved and the main playlist with two separate data structures: the first to load and reference the instances of the video player and the other to be able to manage the main storytelling and decouple it from the videos themselves. A third structure instead regulates key bindings with video clips.
In this way I would be free, if I wish, to manage several playlists or different keybindings.
The rest is rather simple and easy to put together. I have not used frameworks, particular libraries or anything else: good old jQuery and quick and dirty code developed on the train during commuting.