2.0.0 • Published 3 years ago
@eyevinn/video-event-filter v2.0.0
Video Event Filter
A simple module to filter the events sent from the video element in a way that align with what is, most probably, expected from an analytics perspective.
Difference vs default events
The main differences that this filtering brings is
- No
pauseis triggered while not playing. I.e. for seek, buffering or similar. - Instead of
waitingevent we have a properbufferingandbufferedevent flow. timeupdateis only triggered during ongoing playback.- A
playevent afterpauseis now calledresumeto differ from theplayevent.
Implementation
import { VideoEventFilter } from "@eyevinn/video-event-filter";
const videoElement = document.querySelector("video");
const videoEventFilter = new VideoEventFilter(videoElement);
videoEventFilter.addEventListener("*", (event, data) => {
console.log("EVENT:", event);
});Events
These are exposed as an Enum PlayerEvents.
loadingloaded, video have loaded, but not startedplay, video have started to playpauseresume, video have started to play after apauseseekingseeked, video is done seeking. Continue in the state that existed before.bufferingbuffered, video is done buffering. Continue in the state that existed before.timeupdateendederror
States
You can also fetch the current state from the player, which will match the states exposed in PlayerState.
import { VideoEventFilter } from "@eyevinn/video-event-filter";
const videoElement = document.querySelector("video");
const videoEventFilter = new VideoEventFilter(videoElement);
const currentState = videoEventFilter.getState()