solid-primitives
solid-primitives copied to clipboard
`createVideoFrameCallback`
I'd like to contribute a primitive for the requestVideoFrameCallback
API.
Fundamentally it works the same as requestAnimationFrame
, but with some convenient features for videos such as not requesting redundant frames when the video is paused, or polling higher than the video's framerate.
Implementation
Since it's so similar, I'd match the API of createRAF
almost exactly. They might be so similar that they could share a common implementation, but I'd leave the up to the package maintainers and create a parallel version for now.
The only relevant difference might be that if the video element is removed, the callback could be cancelled reactively (for example if it took an Accessor<HTMLVideoElement>
as an input). But maybe that should be left up to the user, since it doesn't really save that much mental overhead, and the user would still need to handle assigning the ref and clearing it in an onCleanup
.
Naming
Any recommendations?
-
createRequestVideoFrameCallback
is a bit of a mouthful, but it's the most descriptive -
createRVFC
matches the naming convention ofcreateRAF
, but it's pretty cryptic at a glance. -
createVideoFrameCallback
is my personal preference, dropping therequest
verb in favor of the conventionalcreate
(ormake
)
Would anyone else find this useful? Any opinions on the best approach?