2020.8.5 • Published 4 years ago

@camtv/video-player v2020.8.5

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

Usage

Installation through NPM

npm install @camtv/video-player --save
import { RenderVideoCamTV, PlayerManager } from "@camtv/video-player";

const player = RenderVideoCamTV({
	id: "my-container-id",
	videoURL: "https://camtv.ams3.cdn.digitaloceanspaces.com/original/CID000016/video/VID0048A6",
	posterURL: "https://media.cam.tv/CID000016/video/VID0048A6/cover.jpg?t=1561462730",
	// ...other options
});
player.on("init", () => {
	console.log("initialized!");
});

Installation as Standalone

<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="video-player.standalone.min.js"></script>
<link href="video-player.standalone.min.css" rel="stylesheet" />

<script>
	var player = RenderVideoCamTV({
		id: "my-container-id",
		videoURL: "https://camtv.ams3.cdn.digitaloceanspaces.com/original/CID000016/video/VID0048A6",
		posterURL: "https://media.cam.tv/CID000016/video/VID0048A6/cover.jpg?t=1561462730",
		// ...other options
	});
	player.on("init", () => {
		console.log("initialized!");
	});
</script>

Configuration

The player can be configured with an object, as you can see below

var player = RenderVideoCamTV({
	id: "",
	videoURL: "",
	posterURL: "",
	autoplay: false,
	muted: false,
	preload: "auto",
	small: false,
	bookmarks: false,
	overlays: false,
	headers: {
		Authorization: "Bearer xxxxx",
	},
	floatingControls: {
		playToggle: true,
		audioToggle: {
			restart: false,
			html: "",
		},
	},
	controls: {
		playToggle: true,
		seekButtons: {
			forward: 30,
			back: 30,
		},
		volumePanel: {
			inline: false,
			vertical: false,
		},
		currentTimeDisplay: true,
		timeDivider: true,
		durationDisplay: true,
		rotation: false,
		videoFit: true,
		sourceMenu: true,
		fullscreenToggle: true,
		pictureInPictureToggle: false,
	},
});

Main video parameters

The first parameters defines all base options about video, such as autoplay or preload. You can find all possible values in the table below:

NamePropsDefaultDescription
idstringnoneContainer id
videoURLstringnoneVideo URL
posterURLstringnoneCover URL
autoplaybool/stringfalsetrue, false, "muted"
mutedboolfalsetrue, false
preloadstringauto"auto", "metadata", "none"
smallboolfalseSmall controls
bookmarksboolfalseStores and shows bookmarks dialog which allow the resume of video
overlaysbool/arrayfalseOverlays object. Includes specific controls' elements. To disable controlBar use false
headersobjectnullHttp request headers
floatingControlsbool/objectobjectFloating controls object. Includes specific controls that are not inside the controls' bar
controlsbool/objectobjectControls object. Includes specific controls' elements. To disable controlBar use false

Floating controls

This options refers to all controls that are not inside the controls' bar, such as big play button or volume toggle button. Setting floatingControls to false will disable all floating buttons.

To enable fine tuning, you have to set an object. Here, you can find all the options:

NamePropsDescription
playToggleboolShow play/pause big center button.
audioTogglebool/objectShow and configure mute/unmute top right button. Object includes restart (restarts video if unmuted), html (inner html content)

Controls' bar

The controls bar can be completely disabled or fine tuned through an object. To disable controls' bar you have to set controls: false. This will display only play and mute overlay buttons on the video, but disables entirely the control bar.

To enable fine tuning for bar, you have to set an object in order to express wich component you want to show or hide. Here, you can find all the options:

NamePropsDescription
playToggleboolShow play/puase button.
seekButtonsbool/objectShow and configure seek buttons. Object includes forward: seconds, back: seconds
volumePanelbool/objectShow and configure volume panel.
currentTimeDisplayboolShow played time indicator
timeDividerboolShow / time divider.
durationDisplayboolShow video duration.
rotationboolShow rotation button.
videoFitboolShow video fit (cover/contain) button.
sourceMenuboolShow video quality source selector if available by video stream (hls only).
fullscreenToggleboolShow fullscreen button.
pictureInPictureToggleboolShow picture-in-picure mode button.

Overlay elements

This options enables some overlay elements during playing, pause, timeupdate or any other event. This options inherits from videojs-overlay library and you could have a looke at that options. This is basically an array of objects. You can set content (inner html), start/end time in seconds or event, div's classes and optionally alignment

overlays: [
	{
		content: "<span>The video is playing</span>",
		start: "play",
		end: "pause",
		class: "my-css-class overlayA",
		align: "bottom-right",
	},
	{
		content: "<span>The video is paused</span>",
		start: "pause",
		end: "play",
		class: "my-css-class overlayE",
		align: "top",
	},
	{
		content: "<span>The video is ended</span>",
		start: "ended",
		end: "play",
		class: "my-css-class overlayD",
		align: "bottom-right",
	},
	{
		content: "<span>The video is 0-40</span>",
		start: 0,
		end: 40,
		class: "my-css-class overlayB",
		align: "top-left",
	},
	{
		content: "<span>The video is 15-30</span>",
		start: 15,
		end: 30,
		class: "my-css-class overlayC",
		align: "bottom-left",
	},
];

Here, you can find all the options:

NamePropsDefaultDescription
contentstringnullHtml string content
startint/stringnullSeconds or events to show overlay.
endint/stringnullSeconds or events to hide overlay.
classstringnullOverlay div's class to merge
alignstringtop-leftAlignment of the balloon.

If you want to simply show a full-player overlay, seta custom css class and overlay css properties.

Methods

This is a list of all public methods for player instance.

MethodDescription
destroy()Removes player events and instance
addEvents()Add player events. This is done automatically on player init constructor
removeEvents()Removes player events
playVideo(seconds)Start playing video. If seconds is passed it start from the given seconds amount
pauseVideo()Pauses video
setMute(toMute)Set mute
getStateVideo()Retrurns the state of video in string format: not_ready, buffering, playing, paused, ended
getBufferPercent()Returns the buffering amount in percent
getVideoDuration()Returns video total duration if available, zero otherwise
getVideoCurrentTime()Returns the number of seconds that have been played.
getFullscreen()Returns if player is in fullscreen
setFullscreen(val)Enables or disables fullscreen mode
isInViewport()Returns if player is visible in viewport

Events and errors handling

You can access player events like a jQuery "on" / "off" method. Replace "eventname" with one of the following names. Props means the elements passed through callback.

player.on("eventname", (evt, ...props) => {
	/*...do something*/
});

Here, you can find all the events:

NamePropsDescription
initnullThe player is initialized and the video is ready
readynullVideo is ready
playnullVideo is playing
pausenullVideo is in pause
endednullVideo is ended
bufferingnullVideo is buffering
trackingobjectTracking played chunks and effectively amount of time. Returns an object like { seconds, chunks }
errorint: errorCodeThere was an error. The events pass an error code. See below.

Contributors