-
Notifications
You must be signed in to change notification settings - Fork 63
/
bitmovinPlayer.js
51 lines (41 loc) · 1.38 KB
/
bitmovinPlayer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React, {useEffect, useRef, useState} from 'react';
import {Player} from 'bitmovin-player';
import {UIFactory} from 'bitmovin-player/bitmovinplayer-ui';
import 'bitmovin-player/bitmovinplayer-ui.css';
function BitmovinPlayer() {
const [player, setPlayer] = useState(null);
const playerConfig = {
key: 'YOUR KEY HERE',
ui: false
};
const playerSource = {
dash: 'https://bitdash-a.akamaihd.net/content/MI201109210084_1/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd',
hls: 'https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8',
poster: 'https://bitdash-a.akamaihd.net/content/MI201109210084_1/poster.jpg'
};
const playerDiv = useRef();
useEffect(() => {
function setupPlayer() {
const playerInstance = new Player(playerDiv.current, playerConfig);
UIFactory.buildDefaultUI(playerInstance);
playerInstance.load(playerSource).then(() => {
setPlayer(playerInstance)
console.log('Successfully loaded source');
}, () => {
console.log('Error while loading source');
});
}
setupPlayer();
return () => {
function destroyPlayer() {
if (player != null) {
player.destroy();
setPlayer(null);
}
}
destroyPlayer();
}
}, [])
return <div id='player' ref={playerDiv}/>;
}
export default BitmovinPlayer;