0.0.10 • Published 2 years ago

kpoint-react-player v0.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

kpoint-react-player

A React component for embeding video in kpoint player.

Usage

npm install kpoint-react-player
import React from 'react';
import ReactDOM from 'react-dom';
import {KpointPlayer} from 'kpoint-react-player'

ReactDOM.render(
  <React.StrictMode>
    <KpointPlayer domain="ktpl.kpoint.com"
    videoId="gcc-d9e8dbc3-5dfa-4f68-bf7a-97f25fb7632c"
    height="360px"
    width="640px"
    offset="50000"
    hide="search, toc, logo"
    />
  </React.StrictMode>,
  document.getElementById('root')
);

Props

PropDescriptionDefault
domainHost name of your kPoint server. Typically of the form acme.kpoint.com.""
vidoeIdId of the video to load.""
widthSet the width of the player640px
heightSet the height of the player360px
playerParamsSet the player parameters{}
widgetsConfigSet the widgets configuration{}

Callback props

Callback props take a function that gets fired on various player events:

PropDescription
onLoadCalled when media is loaded and ready to play.
onErrorCalled when an error occurs whilst attempting to play media
onStateChangeCalled when playback state updates (-1: Not started yet, 0: Playback Over, 1: Playing, 2: Paused, 3: Buffering, 5: Replay)
onTimeupdatecalled when playback time updates

Instance Methods

Use ref to call instance methods on the player.

MethodDescription
getIdReturns the video player id
getInfoReturns the video player info
playVideoPlays video from current position. or if video has not started, starts video from beginning.
pauseVideoPauses video at the current position.
replayVideoReplays video from the beginning.
getCurrentTimeReturns current video position in milliseconds.
getDurationReturns the duration of the video in milliseconds.
getVolumeReturns current volume level in the range 0 to 1 - 0 is considered muted and 1 as full volume.
seekToJumps to specific point in video. Time argument in specified in milliseconds.
setVolumeSet volume level to specified, input should be between 0 and 1.

Example of how to use callback props and Instance methods to control the player

import React, { useRef } from "react";
import { KpointPlayer } from "kpoint-react-player";

function App() {
  function onTimeupdate(timeMs) {
    console.log("Time update, new time: " + parseFloat(timeMs).toFixed(2));
  }
  function onStateChange(evt) {
    console.log("onStateChange: " + evt.data);
  }
  function onError(evt) {
    console.log("onError: " + evt.data);
  }
  function onload() {
    console.log("Video loaded");
  }
  const playerRef = useRef();
  return (
    <>
      <button
        onClick={() => {
          console.log(playerRef.current.getDuration());
        }}
      >
        Get Video Duration
      </button>
      <KpointPlayer
        ref={playerRef}
        domain="ktpl.kpoint.com"
        videoId="gcc-d9e8dbc3-5dfa-4f68-bf7a-97f25fb7632c"
        height="360px"
        width="640px"
        playerParams={{ search: "false", toc: "false" }}
        onStateChange={onStateChange}
        onTimeupdate={onTimeupdate}
        onload={onload}
        onError={onError}
      />
    </>
  );
}
export default App;

Events

If you wish you access the player object to control it programatically, include a onkPointPlayerReady method in page or Javascript. This method will be called and it will be passed the player when it is created and ready to be used.

function onkPointPlayerReady(player) {
  console.log("Got instance of a player: " + player.id);
  player.startVideo();
}

License

React is MIT licensed.