videojs-watch-percentage

1.0.13 • Public • Published

videojs-watch-percentage

A simple npm package to track the percentage of a video watched using Video.js.

Installation

You can install videojs-watch-percentage via npm or yarn:

npm install videojs-watch-percentage

or

yarn add videojs-watch-percentage

Usage

const videoTracker = require('videojs-watch-percentage');

const videoElement = document.getElementById('my-video');
videoTracker(videoElement);

videoElement.addEventListener('videoended', event => {
    console.log('Total Watched:', event.detail.totalWatched);
    console.log('Skipped Sections:', event.detail.skippedSections);
});

Usage React

const videoRef = useRef(null);

useEffect(() => {
    const videoElement = videoRef.current;
    videoTracker(videoElement);
    return () => {
        videoElement.removeEventListener('videoended', onVideoEnded);
    };
}, []); 

const onVideoEnded = event => {
    console.log('Total Watched:', event.detail.totalWatched);
    console.log('Skipped Sections:', event.detail.skippedSections);
};

Usage Vue

mounted() {
    const videoElement = this.$refs.videoPlayer;
    videoTracker(videoElement);
    videoElement.addEventListener('videoended', this.onVideoEnded);
},
beforeDestroy() {
    const videoElement = this.$refs.videoPlayer;
    videoElement.removeEventListener('videoended', this.onVideoEnded);
},
methods: {
    onVideoEnded(event) {
        console.log('Total Watched:', event.detail.totalWatched);
        console.log('Skipped Sections:', event.detail.skippedSections);
    }
}

License

This package is licensed under the MIT License.

Package Sidebar

Install

npm i videojs-watch-percentage

Weekly Downloads

1

Version

1.0.13

License

MIT

Unpacked Size

3.09 kB

Total Files

3

Last publish

Collaborators

  • sakib44