├── .DS_Store
├── .gitignore
├── LICENSE
├── README.md
├── basic-implementation
├── README.md
├── package.json
├── public
│ ├── favicon.ico
│ └── index.html
└── src
│ ├── components
│ └── VideoPlayer.js
│ └── index.js
├── nextjs-shaka-player
├── .DS_Store
├── README.md
├── containers
│ └── Tutorial
│ │ └── index.jsx
├── package-lock.json
├── package.json
├── pages
│ ├── _app.jsx
│ └── index.jsx
└── public
│ └── styles
│ └── index.css
├── with-default-ui
├── README.md
├── package.json
├── public
│ ├── favicon.ico
│ └── index.html
└── src
│ ├── components
│ └── VideoPlayer.js
│ ├── index.css
│ └── index.js
└── with-ui-configuration
├── README.md
├── package.json
├── public
├── favicon.ico
└── index.html
└── src
├── components
└── VideoPlayer.js
├── index.css
└── index.js
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amit08255/shaka-player-react-with-ui-config/950f41f51b2af8f2859a40c0c27684108e735ee6/.DS_Store
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | .git/
3 | .idea/
4 | .next/
5 | yarn.lock
6 | node_modules/
7 | /nbproject/private/
8 | /build/
9 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Amit Kumar
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # shaka-player-react-with-ui-config
2 | Shaka player implementation in ReactJS. This repository contains basic shaka player implementation and also implementation of shaka player in ReactJS with custom UI configuration.
3 |
--------------------------------------------------------------------------------
/basic-implementation/README.md:
--------------------------------------------------------------------------------
1 | ## Basic implementation of Shaka Player in ReactJS
2 |
3 | This is simple ReactJS app with basic implementation of shaka player. In this app, we are just loading a simple video in shaka player in our app.
4 |
5 | ## Installing app
6 |
7 | Before using this app, you need to install dependencies. Use below command to install dependencies -
8 |
9 | ```sh
10 | npm install
11 | ```
12 |
13 | ## Starting app
14 |
15 | To use this app, use below command -
16 |
17 | ```sh
18 | npm start
19 | ```
20 |
21 | It will start our app which can be accessed in browser at - http://localhost:3000
22 |
23 |
24 | # Internal details
25 |
26 | Read further details to know how you can implement shaka player in your ReactJS app.
27 |
28 | **Note** - Remember, if your ReactJS app uses server-side rendering, you must always load your shaka player component on client side.
29 |
30 | ## Adding shaka player in your React app
31 |
32 | For using shaka player in your app, you need to install shaka-player using command -
33 |
34 | ```sh
35 | npm install --save shaka-player
36 | ```
37 |
38 | ## Simple React component with shaka player
39 |
40 | ```js
41 |
42 | //importing dependencies
43 |
44 | import React from 'react';
45 | import shaka from 'shaka-player';
46 |
47 |
48 | //Creating class component
49 |
50 | class VideoPlayer extends React.PureComponent{
51 |
52 | constructor(props){
53 |
54 | super(props);
55 |
56 | //Creating reference which will allow access to video player on DOM
57 | this.videoComponent = React.createRef();
58 |
59 | //Adding reference to event handler functions
60 | this.onErrorEvent = this.onErrorEvent.bind(this);
61 | this.onError = this.onError.bind(this);
62 | }
63 |
64 | onErrorEvent(event) {
65 | // Extract the shaka.util.Error object from the event.
66 | this.onError(event.detail);
67 | }
68 |
69 | onError(error) {
70 | // Log the error.
71 | console.error('Error code', error.code, 'object', error);
72 | }
73 |
74 | //Initialize your shaka player here
75 | componentDidMount(){
76 |
77 | //MPEG-DASH video URL
78 | var manifestUri = 'https://storage.googleapis.com/shaka-demo-assets/angel-one/dash.mpd';
79 |
80 | //Reference to our video component on DOM
81 | const video = this.videoComponent.current;
82 |
83 | //Initializing our shaka player
84 | var player = new shaka.Player(video);
85 |
86 | // Listen for error events.
87 | player.addEventListener('error', this.onErrorEvent);
88 |
89 | // Try to load a manifest.
90 | // This is an asynchronous process.
91 | player.load(manifestUri).then(function() {
92 | // This runs if the asynchronous load is successful.
93 | console.log('The video has now been loaded!');
94 | }).catch(this.onError); // onError is executed if the asynchronous load fails.
95 |
96 | }
97 |
98 | render(){
99 |
100 |
101 | /*Returning video component. Shaka player will be added to this component
102 | once its mounted on DOM
103 | */
104 | return(
105 |
111 | );
112 | }
113 | }
114 |
115 | export default VideoPlayer;
116 | ```
117 |
118 | **Note -** For more details on shaka player, follow the documentation provided -
119 | https://shaka-player-demo.appspot.com/docs/api/index.html
120 | Remember that the documentation refer to JavaScript implementation of shaka player, implementation method may differ for ReactJS but APIs will be same.
121 |
--------------------------------------------------------------------------------
/basic-implementation/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "shaka-player-react-with-ui-config",
3 | "version": "1.0.0",
4 | "description": "Shaka player implementation in ReactJS. This repository contains basic shaka player implementation and also implementation of shaka player in ReactJS with custom UI configuration.",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "react-scripts start",
8 | "build": "react-scripts build",
9 | "test": "react-scripts test --env=jsdom",
10 | "eject": "react-scripts eject"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "git+https://github.com/amit08255/shaka-player-react-with-ui-config.git"
15 | },
16 | "keywords": [
17 | "Shaka",
18 | "player",
19 | "ReactJS"
20 | ],
21 | "author": "Amit Kumar",
22 | "license": "MIT",
23 | "bugs": {
24 | "url": "https://github.com/amit08255/shaka-player-react-with-ui-config/issues"
25 | },
26 | "homepage": "https://github.com/amit08255/shaka-player-react-with-ui-config#readme",
27 | "dependencies": {
28 | "react": "^16.9.0",
29 | "react-dom": "^16.9.0",
30 | "react-scripts": "^3.4.1",
31 | "shaka-player": "^2.5.5"
32 | },
33 | "devDependencies": {}
34 | }
35 |
--------------------------------------------------------------------------------
/basic-implementation/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amit08255/shaka-player-react-with-ui-config/950f41f51b2af8f2859a40c0c27684108e735ee6/basic-implementation/public/favicon.ico
--------------------------------------------------------------------------------
/basic-implementation/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
16 | React App
17 |
18 |
19 |
20 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/basic-implementation/src/components/VideoPlayer.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import shaka from 'shaka-player';
3 |
4 | class VideoPlayer extends React.PureComponent{
5 |
6 | constructor(props){
7 |
8 | super(props);
9 |
10 | this.videoComponent = React.createRef();
11 |
12 | this.onErrorEvent = this.onErrorEvent.bind(this);
13 |
14 | this.onError = this.onError.bind(this);
15 | }
16 |
17 | onErrorEvent(event) {
18 | // Extract the shaka.util.Error object from the event.
19 | this.onError(event.detail);
20 | }
21 |
22 | onError(error) {
23 | // Log the error.
24 | console.error('Error code', error.code, 'object', error);
25 | }
26 |
27 | componentDidMount(){
28 |
29 | var manifestUri = 'https://storage.googleapis.com/shaka-demo-assets/angel-one/dash.mpd';
30 |
31 | const video = this.videoComponent.current;
32 |
33 | var player = new shaka.Player(video);
34 |
35 | // Listen for error events.
36 | player.addEventListener('error', this.onErrorEvent);
37 |
38 | // Try to load a manifest.
39 | // This is an asynchronous process.
40 | player.load(manifestUri).then(function() {
41 | // This runs if the asynchronous load is successful.
42 | console.log('The video has now been loaded!');
43 | }).catch(this.onError); // onError is executed if the asynchronous load fails.
44 |
45 | }
46 |
47 | render(){
48 |
49 | return(
50 |
56 | );
57 | }
58 | }
59 |
60 | export default VideoPlayer;
--------------------------------------------------------------------------------
/basic-implementation/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import VideoPlayer from './components/VideoPlayer';
4 |
5 | ReactDOM.render(
6 | ,
7 | document.getElementById('root')
8 | );
9 |
--------------------------------------------------------------------------------
/nextjs-shaka-player/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amit08255/shaka-player-react-with-ui-config/950f41f51b2af8f2859a40c0c27684108e735ee6/nextjs-shaka-player/.DS_Store
--------------------------------------------------------------------------------
/nextjs-shaka-player/README.md:
--------------------------------------------------------------------------------
1 | # shaka player implementation with NextJS
2 |
3 | This simple project contains basic implementation of shaka player with NextJS. Since NextJS has built-in support for SSR, and shaka player doesnt support it, you need to load shaka player with -
4 |
5 | ```js
6 | import dynamic from 'next/dynamic';
7 | ```
8 |
9 | With it you can import JavaScript modules (inc. React Components) dynamically and work with them. They also work with SSR. You can think of dynamic imports as another way to split your code into manageable chunks.
10 |
11 | `containers/Tutorial.js` loads shaka player with video from props. We are loading this container dynamically in our index page so that shaka player is loaded without any issue with SSR.
12 |
13 |
14 | ## Installing app
15 |
16 | Before using this app, you need to install dependencies. Use below command to install dependencies -
17 |
18 | ```sh
19 | npm install
20 | ```
21 |
22 | ## Starting app
23 |
24 | To use this app, use below command -
25 |
26 | ```sh
27 | npm run dev
28 | ```
29 |
30 | It will start our app which can be accessed in browser at - http://localhost:3000
31 |
--------------------------------------------------------------------------------
/nextjs-shaka-player/containers/Tutorial/index.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | const shaka = require('shaka-player/dist/shaka-player.ui.js');
4 |
5 | class Tutorial extends React.PureComponent{
6 |
7 | constructor(props){
8 |
9 | super(props);
10 |
11 | this.video = React.createRef();
12 | this.videoContainer = React.createRef();
13 | }
14 |
15 | componentDidMount(){
16 |
17 | var manifestUri = this.props.manifestUrl;
18 | var licenseServer = this.props.licenseServer;
19 |
20 | let video = this.video.current;
21 | let videoContainer = this.videoContainer.current;
22 |
23 | var player = new shaka.Player(video);
24 |
25 | const ui = new shaka.ui.Overlay(player, videoContainer, video);
26 | const controls = ui.getControls();
27 |
28 | console.log(Object.keys(shaka.ui));
29 |
30 | player.configure({
31 | drm: {
32 | servers: { 'com.widevine.alpha': licenseServer }
33 | }
34 | });
35 |
36 |
37 | const onError = (error) => {
38 | // Log the error.
39 | console.error('Error code', error.code, 'object', error);
40 | }
41 |
42 | player.load(manifestUri).then(function() {
43 | // This runs if the asynchronous load is successful.
44 | console.log('The video has now been loaded!');
45 | }).catch(onError); // onError is executed if the asynchronous load fails.
46 | }
47 |
48 | render(){
49 |
50 | return(
51 |
124 | );
125 | }
126 | }
127 |
128 | export default VideoPlayer;
129 | ```
130 |
131 |
132 | **Note -** For more details on shaka player, follow the documentation provided -
133 | https://shaka-player-demo.appspot.com/docs/api/index.html
134 | Remember that the documentation refer to JavaScript implementation of shaka player, implementation method may differ for ReactJS but APIs will be same.
135 |
--------------------------------------------------------------------------------
/with-default-ui/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "shaka-player-react-with-ui-config",
3 | "version": "1.0.0",
4 | "description": "Shaka player implementation in ReactJS. This repository contains basic shaka player implementation and also implementation of shaka player in ReactJS with custom UI configuration.",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "react-scripts start",
8 | "build": "react-scripts build",
9 | "test": "react-scripts test --env=jsdom",
10 | "eject": "react-scripts eject"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "git+https://github.com/amit08255/shaka-player-react-with-ui-config.git"
15 | },
16 | "keywords": [
17 | "Shaka",
18 | "player",
19 | "ReactJS"
20 | ],
21 | "author": "Amit Kumar",
22 | "license": "MIT",
23 | "bugs": {
24 | "url": "https://github.com/amit08255/shaka-player-react-with-ui-config/issues"
25 | },
26 | "homepage": "https://github.com/amit08255/shaka-player-react-with-ui-config#readme",
27 | "dependencies": {
28 | "react": "^16.9.0",
29 | "react-dom": "^16.9.0",
30 | "react-scripts": "^3.4.1",
31 | "shaka-player": "^2.5.5"
32 | },
33 | "devDependencies": {}
34 | }
35 |
--------------------------------------------------------------------------------
/with-default-ui/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amit08255/shaka-player-react-with-ui-config/950f41f51b2af8f2859a40c0c27684108e735ee6/with-default-ui/public/favicon.ico
--------------------------------------------------------------------------------
/with-default-ui/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
16 | React App
17 |
18 |
19 |
20 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/with-default-ui/src/components/VideoPlayer.js:
--------------------------------------------------------------------------------
1 | /*
2 | If you are using server-side rendering, remember that this component should be loaded on client-side
3 | shaka player needs to be loaded on client-side, loading it on server-side may lead to error or undesired results
4 | */
5 |
6 |
7 | /*
8 | importing dependencies and CSS file(s) required for UI customization
9 | */
10 | import React from 'react';
11 | import 'shaka-player/dist/controls.css';
12 | const shaka = require('shaka-player/dist/shaka-player.ui.js');
13 |
14 | //Creating class component
15 | class VideoPlayer extends React.PureComponent{
16 |
17 | constructor(props){
18 |
19 | super(props);
20 |
21 | //Creating reference to store video component on DOM
22 | this.videoComponent = React.createRef();
23 |
24 | //Creating reference to store video container on DOM
25 | this.videoContainer = React.createRef();
26 |
27 | //Initializing reference to error handlers
28 | this.onErrorEvent = this.onErrorEvent.bind(this);
29 | this.onError = this.onError.bind(this);
30 | }
31 |
32 | onErrorEvent(event) {
33 | // Extract the shaka.util.Error object from the event.
34 | this.onError(event.detail);
35 | }
36 |
37 | onError(error) {
38 | // Log the error.
39 | console.error('Error code', error.code, 'object', error);
40 | }
41 |
42 | componentDidMount(){
43 |
44 | //Link to MPEG-DASH video
45 | var manifestUri = 'https://storage.googleapis.com/shaka-demo-assets/angel-one/dash.mpd';
46 |
47 | //Getting reference to video and video container on DOM
48 | const video = this.videoComponent.current;
49 | const videoContainer = this.videoContainer.current;
50 |
51 | //Initialize shaka player
52 | var player = new shaka.Player(video);
53 |
54 | //Setting up shaka player UI
55 | const ui = new shaka.ui.Overlay(player, videoContainer, video);
56 | ui.getControls();
57 |
58 | // Listen for error events.
59 | player.addEventListener('error', this.onErrorEvent);
60 |
61 | // Try to load a manifest.
62 | // This is an asynchronous process.
63 | player.load(manifestUri).then(function() {
64 | // This runs if the asynchronous load is successful.
65 | console.log('The video has now been loaded!');
66 | }).catch(this.onError); // onError is executed if the asynchronous load fails.
67 |
68 | }
69 |
70 | render(){
71 |
72 | /*
73 | Returning video with a container. Remember, when setting up shaka player with custom UI, you must
74 | add your video component inside a container
75 | The container will be used by shaka player to add your customized UI for the player
76 | */
77 | return(
78 |
79 |
84 |
85 | );
86 | }
87 | }
88 |
89 | export default VideoPlayer;
90 |
--------------------------------------------------------------------------------
/with-default-ui/src/index.css:
--------------------------------------------------------------------------------
1 | .video-container{
2 | width: 640px;
3 | margin: auto;
4 | max-width: 100%;
5 | }
6 |
7 | .shaka-video{
8 | width: 100%;
9 | height: 100%;
10 | }
--------------------------------------------------------------------------------
/with-default-ui/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import VideoPlayer from './components/VideoPlayer';
4 | import './index.css';
5 |
6 | ReactDOM.render(
7 | ,
8 | document.getElementById('root')
9 | );
10 |
--------------------------------------------------------------------------------
/with-ui-configuration/README.md:
--------------------------------------------------------------------------------
1 | ## Implementation of Shaka Player in ReactJS with UI configuration
2 |
3 | This is simple ReactJS app with implementation of shaka player with UI configuration. In this app, we are using shaka player and see how we can configure shaka player UI the easy way.
4 |
5 | ## Installing app
6 |
7 | Before using this app, you need to install dependencies. Use below command to install dependencies -
8 |
9 | ```sh
10 | npm install
11 | ```
12 |
13 | ## Starting app
14 |
15 | To use this app, use below command -
16 |
17 | ```sh
18 | npm start
19 | ```
20 |
21 | It will start our app which can be accessed in browser at - http://localhost:3000
22 |
23 |
24 | # Internal details
25 |
26 | Read further details to know how you can implement shaka player in your ReactJS app.
27 |
28 | **Note** - Remember, if your ReactJS app uses server-side rendering, you must always load your shaka player component on client side.
29 |
30 | ## Adding shaka player in your React app
31 |
32 | For using shaka player in your app, you need to install shaka-player using command -
33 |
34 | ```sh
35 | npm install --save shaka-player
36 | ```
37 |
38 | ## Simple React component with shaka player
39 |
40 | ```js
41 |
42 | /*
43 | If you are using server-side rendering, remember that this component should be loaded on client-side
44 | shaka player needs to be loaded on client-side, loading it on server-side may lead to error or undesired results
45 | */
46 |
47 |
48 | /*
49 | importing dependencies and CSS file(s) required for UI customization
50 | */
51 | import React from 'react';
52 | import 'shaka-player/dist/controls.css';
53 | const shaka = require('shaka-player/dist/shaka-player.ui.js');
54 |
55 | //Creating class component
56 | class VideoPlayer extends React.PureComponent{
57 |
58 | constructor(props){
59 |
60 | super(props);
61 |
62 | //Creating reference to store video component on DOM
63 | this.videoComponent = React.createRef();
64 |
65 | //Creating reference to store video container on DOM
66 | this.videoContainer = React.createRef();
67 |
68 | //Initializing reference to error handlers
69 | this.onErrorEvent = this.onErrorEvent.bind(this);
70 | this.onError = this.onError.bind(this);
71 | }
72 |
73 | onErrorEvent(event) {
74 | // Extract the shaka.util.Error object from the event.
75 | this.onError(event.detail);
76 | }
77 |
78 | onError(error) {
79 | // Log the error.
80 | console.error('Error code', error.code, 'object', error);
81 | }
82 |
83 | componentDidMount(){
84 |
85 | //Link to MPEG-DASH video
86 | var manifestUri = 'https://storage.googleapis.com/shaka-demo-assets/angel-one/dash.mpd';
87 |
88 | //Getting reference to video and video container on DOM
89 | const video = this.videoComponent.current;
90 | const videoContainer = this.videoContainer.current;
91 |
92 | //Initialize shaka player
93 | var player = new shaka.Player(video);
94 |
95 | //Setting UI configuration JSON object
96 | const uiConfig = {};
97 |
98 | //Configuring elements to be displayed on video player control panel
99 | uiConfig['controlPanelElements'] = ['mute', 'volume', 'time_and_duration', 'fullscreen', 'overflow_menu', ];
100 |
101 | //Setting up shaka player UI
102 | const ui = new shaka.ui.Overlay(player, videoContainer, video);
103 |
104 | ui.configure(uiConfig); //configure UI
105 | ui.getControls();
106 |
107 | // Listen for error events.
108 | player.addEventListener('error', this.onErrorEvent);
109 |
110 | // Try to load a manifest.
111 | // This is an asynchronous process.
112 | player.load(manifestUri).then(function() {
113 | // This runs if the asynchronous load is successful.
114 | console.log('The video has now been loaded!');
115 | }).catch(this.onError); // onError is executed if the asynchronous load fails.
116 |
117 | }
118 |
119 | render(){
120 |
121 | /*
122 | Returning video with a container. Remember, when setting up shaka player with custom UI, you must
123 | add your video component inside a container
124 | The container will be used by shaka player to add your customized UI for the player
125 | */
126 | return(
127 |
128 |
133 |
134 | );
135 | }
136 | }
137 |
138 | export default VideoPlayer;
139 | ```
140 |
141 | ## More about video player control panel customization
142 |
143 | The following elements can be added to the UI bar using this configuration value:
144 |
145 | * **time_and_duration:** adds an element tracking and displaying current progress of the presentation and the full presentation duration in the "0:10 / 1:00" form where "0:10" (ten seconds) is the number of seconds passed from the start of the presentation and "1:00" (one minute) is the presentation duration.
146 |
147 | * **play_pause:** adds a button that plays/pauses the video on click.
148 |
149 | * **mute:** adds a button that mutes/unmutes the video on click.
150 |
151 | * **volume:** adds a volume slider.
152 |
153 | * **fullscreen:** adds a button that toggles full screen mode on click.
154 |
155 | * **overflow_menu:** adds a button that opens an overflow menu with additional settings buttons. It's content is also configurable.
156 |
157 | * **rewind:** adds a button that rewinds the presentation on click; that is, it starts playing the presentation backwards.
158 |
159 | * **fast_forward:** adds a button that fast forwards the presentation on click; that is, it starts playing the presentation at an increased speed
160 |
161 | * **spacer:** adds a chunk of empty space between the adjacent elements.
162 |
163 | ## More on configuring overflow menu of shaka player
164 |
165 | Similarly, the 'overflowMenuButtons' configuration option can be used to control the contents of the overflow menu. The following buttons can be added to the overflow menu:
166 |
167 | * **captions:** adds a button that controls the current text track selection (including turning it off). The button is visible only if the content has at least one text track.
168 |
169 | * **cast:** adds a button that opens a Chromecast dialog. The button is visible only if there is at least one Chromecast device on the same network available for casting.
170 |
171 | * **quality:** adds a button that controls enabling/disabling of abr and video resolution selection.
172 |
173 | * **language:** adds a button that controls audio language selection.
174 |
175 | * **picture_in_picture:** adds a button that enables/disables picture-in-picture mode on browsers that support it. Button is invisible on other browsers.
176 |
177 |
178 |
179 | **Note -** For more details on shaka player, follow the documentation provided -
180 | https://shaka-player-demo.appspot.com/docs/api/index.html
181 | Remember that the documentation refer to JavaScript implementation of shaka player, implementation method may differ for ReactJS but APIs will be same.
182 |
--------------------------------------------------------------------------------
/with-ui-configuration/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "shaka-player-react-with-ui-config",
3 | "version": "1.0.0",
4 | "description": "Shaka player implementation in ReactJS. This repository contains basic shaka player implementation and also implementation of shaka player in ReactJS with custom UI configuration.",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "react-scripts start",
8 | "build": "react-scripts build",
9 | "test": "react-scripts test --env=jsdom",
10 | "eject": "react-scripts eject"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "git+https://github.com/amit08255/shaka-player-react-with-ui-config.git"
15 | },
16 | "keywords": [
17 | "Shaka",
18 | "player",
19 | "ReactJS"
20 | ],
21 | "author": "Amit Kumar",
22 | "license": "MIT",
23 | "bugs": {
24 | "url": "https://github.com/amit08255/shaka-player-react-with-ui-config/issues"
25 | },
26 | "homepage": "https://github.com/amit08255/shaka-player-react-with-ui-config#readme",
27 | "dependencies": {
28 | "react": "^16.9.0",
29 | "react-dom": "^16.9.0",
30 | "react-scripts": "^3.4.1",
31 | "shaka-player": "^2.5.5"
32 | },
33 | "devDependencies": {}
34 | }
35 |
--------------------------------------------------------------------------------
/with-ui-configuration/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amit08255/shaka-player-react-with-ui-config/950f41f51b2af8f2859a40c0c27684108e735ee6/with-ui-configuration/public/favicon.ico
--------------------------------------------------------------------------------
/with-ui-configuration/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
16 | React App
17 |
18 |
19 |
20 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/with-ui-configuration/src/components/VideoPlayer.js:
--------------------------------------------------------------------------------
1 | /*
2 | If you are using server-side rendering, remember that this component should be loaded on client-side
3 | shaka player needs to be loaded on client-side, loading it on server-side may lead to error or undesired results
4 | */
5 |
6 |
7 | /*
8 | importing dependencies and CSS file(s) required for UI customization
9 | */
10 | import React from 'react';
11 | import 'shaka-player/dist/controls.css';
12 | const shaka = require('shaka-player/dist/shaka-player.ui.js');
13 |
14 | //Creating class component
15 | class VideoPlayer extends React.PureComponent{
16 |
17 | constructor(props){
18 |
19 | super(props);
20 |
21 | //Creating reference to store video component on DOM
22 | this.videoComponent = React.createRef();
23 |
24 | //Creating reference to store video container on DOM
25 | this.videoContainer = React.createRef();
26 |
27 | //Initializing reference to error handlers
28 | this.onErrorEvent = this.onErrorEvent.bind(this);
29 | this.onError = this.onError.bind(this);
30 | }
31 |
32 | onErrorEvent(event) {
33 | // Extract the shaka.util.Error object from the event.
34 | this.onError(event.detail);
35 | }
36 |
37 | onError(error) {
38 | // Log the error.
39 | console.error('Error code', error.code, 'object', error);
40 | }
41 |
42 | componentDidMount(){
43 |
44 | //Link to MPEG-DASH video
45 | var manifestUri = 'https://storage.googleapis.com/shaka-demo-assets/angel-one/dash.mpd';
46 |
47 | //Getting reference to video and video container on DOM
48 | const video = this.videoComponent.current;
49 | const videoContainer = this.videoContainer.current;
50 |
51 | //Initialize shaka player
52 | var player = new shaka.Player(video);
53 |
54 | //Setting UI configuration JSON object
55 | const uiConfig = {};
56 |
57 | //Configuring elements to be displayed on video player control panel
58 | uiConfig['controlPanelElements'] = ['mute', 'volume', 'time_and_duration', 'fullscreen', 'overflow_menu', ];
59 |
60 | //Setting up shaka player UI
61 | const ui = new shaka.ui.Overlay(player, videoContainer, video);
62 |
63 | ui.configure(uiConfig); //configure UI
64 | ui.getControls();
65 |
66 | // Listen for error events.
67 | player.addEventListener('error', this.onErrorEvent);
68 |
69 | // Try to load a manifest.
70 | // This is an asynchronous process.
71 | player.load(manifestUri).then(function() {
72 | // This runs if the asynchronous load is successful.
73 | console.log('The video has now been loaded!');
74 | }).catch(this.onError); // onError is executed if the asynchronous load fails.
75 |
76 | }
77 |
78 | render(){
79 |
80 | /*
81 | Returning video with a container. Remember, when setting up shaka player with custom UI, you must
82 | add your video component inside a container
83 | The container will be used by shaka player to add your customized UI for the player
84 | */
85 | return(
86 |