I would like to represent the timestamp coming from an HTMLMediaElement
. Its defining characteristics are:
- Its value is represented as a
Double
- It can be queried at any time using
getCurrentTime :: IO Double
(as partially applied on a givenHTMLMediaElement
) - It is potentially continuously changing (whenever the media player is playing)
My initial plan was to represent it as a Behavior t Double
that re-runs the IO Double
every time it is observed, but that hasn't worked out too well.
Things I've tried:
- Using a
Behavior
that is prodded under the hood at a fixed frequency, as described in the workaround section of this question - Passing an
Event t ()
representing the desired sampling frequency, and returning anEvent t Double
that holds the coinciding timestamps
I don't really like either -- the first one either couples the behaviour (sorry) too much to my specific use case (if I use the eventual sampling frequency I'll use in my app) or seems wasteful (if I use something like 1 kHz sampling when creating the Behavior
just to then sample it at 60 Hz on the application end), and the second is quite inflexible if you want to do more than one thing with the timestamp at different sampling rates.