The is the player widget used by the RotoscodeJS Recorder (VS Code Extension).
- Exposes an
onRenderhook so you can format the code frame-by-frame (like highlight it using a 3rd party code highlighter) - Fully controllable using its several control functions
<script src="PATH_TO_ROTOSCODEJS_WIDGET_SCRIPT" type="text/javascript"></script>
<script type="text/javascript">
var recordingData = {truncated for simplicity};
var rotoscodejsObj = rotoscodejs({
element: document.getElementById('codeplayer'),
recordingData: recordingData,
onRender: (el) => {
// use any highlighter code
// Example:
// hljs.highlightElement(el);
},
onPlay: (runningTimestamp, endTimestamp) => {
// render timestamp somewhere
}
});
</script>
The above code snippet is already provided by the RotoscodeJS Recorder (VS Code Extension). To further understand what's happening here, let's break it down.
There are 4 things you need to define to instantiate a RotoscodeJS player:
- The
elementis basically the HTML element where each frame will be rendered on. - The
recordingDatawhich is the actual frame-by-frame change logged by the recorder. - The
onRenderhook. This hook allows for custom processing of the rendered frame. The hook receives theelvariable which is the HTML element defined earlier. This hook is optional. - The
onPlayhook. This hook receives therunningTimeStampand theendTimestampwhich allows for displaying the actual playback time somewhere on your page. This hook is optional.
To control the RotoscodeJS player, you can call any of the functions below.
| Function | Description |
|---|---|
| play | Start or continue playback. Has 1 optional parameter (isLooped) which sets the playback to loop. |
| pause | Pauses the playback. |
| jump | Jump to a specific timestamp. Playback will be paused. |
| stop | Stops the playback. |
| updateData | Changes the recording data used by the player. Playback will be paused at the first frame of the new recording data. |
For full examples, you can check the samples directory.