Bayes Web Player
What is Bayes Web Player?
Bayes Web Player is a lightweight, feature-rich frontend library that is developed in-house specifically to embed video streams from Bayes Video on your site. Offering an effortless integration, the player is written using TypeScript without any frontend framework restrictions and will be made available as an NPM package as well as via CDN.
Features
Playback Features
- Autoplay ON/OFF as required.
- Detachable player.
- Comprehensive API for stream playback control, volume control, UI control etc.
User Interface
- Fullscreen.
- Volume controls.
- Custom error message.
- Custom styling.
- Thumbnail.
- Watermarking.
Integration
Installation
You can install the library and the default stylesheets for the Bayes Web Player via CDN and as an NPM package.
Installing as an NPM package
npm i @bayesgg/bayes-web-player-js
via CDN
<script src="https://cdn.jsdelivr.net/npm/@bayesgg/bayes-web-player-js@0.1.3/dist/bwp.js" crossorigin></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@bayesgg/bayes-web-player-js@0.1.3/dist/css/bwp.css" />
Usage
The Bayes Web Player offers an easy to integrate interface which can be either imported (NPM) or referred to via the global instance. You can find minimal examples given below.
JS integration via CDN
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- CDN import for the minified JS files of the Bayes Web Player -->
<script
src="https://cdn.jsdelivr.net/npm/@bayesgg/bayes-web-player-js/dist/bwp.js"
crossorigin
></script>
<!-- CDN import for the minified stylesheet of the Bayes Web Player -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@bayesgg/bayes-web-player-js/dist/css/bwp.css"
/>
<script>
const player = new bwp(
/**
* Playlist URL fetched via Bayes Video
* */
'insert-playlist-url-here',
/**
* Container ID where the player will be embedded
* */
'root',
/**
* Options for the player to be initialized. You can find a comprehensive
* list of available options provided later in the documentation
**/
{
autoplay: true
}
);
// Initialise and play the video.
player.init();
player.play();
</script>
<title>Bayes Web Player Demo! :)</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
React Integration via NPM
import { useEffect, useRef } from 'react';
import BayesWebPlayer from '@bayesgg/bayes-web-player-js';
/**
* Import the default stylesheet from Bayes Web Player
*/
import '@bayesgg/bayes-web-player-js/dist/css/bwp.css';
function Stream() {
const ref = useRef();
useEffect(() => {
/**
* Instantiate player with the container ref
*/
const player = new BayesWebPlayer(
/**
* Playlist URL fetched via Bayes Video
*/
'insert-playlist-url-here',
ref.current,
{
autoplay: true,
muted: true
}
);
player.init();
player.play();
/**
* Make sure the player is destroyed on component unmount
*/
return () => {
player.destroy();
};
}, []);
return <div ref={ref} />;
}
export default Stream;
Integration within iFrames
When instantiating the Player within an iframe
using the id
container reference instead of directly passing the HTMLDivElement
, please make sure to pass the ownerDocument
object of iframe
as the 4th constructor parameter.
This is done in order to avoid styling conflicts as the computed styles will be added to the original document where the iframe
is embedded. This can be overlooked if the player is instantiated with an HTMLDivElement
is directly being passed instead of the id
reference, as the document will always be fetched via the HTMLDivElement
.
Further, it is also important to keep in mind to pass the isWithinIFrame
option as true
within PlayerOptions.