-
Notifications
You must be signed in to change notification settings - Fork 63
/
bitmovinPlayer.js
65 lines (54 loc) · 1.48 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React from 'react';
import {Player} from 'bitmovin-player';
import {UIFactory} from 'bitmovin-player/bitmovinplayer-ui';
import 'bitmovin-player/bitmovinplayer-ui.css';
class BitmovinPlayer extends React.Component {
state = {
player: null,
};
playerConfig = {
key: 'YOUR KEY HERE',
ui: false
};
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'
};
constructor(props) {
super(props);
this.playerDiv = React.createRef();
}
componentDidMount() {
this.setupPlayer();
}
componentWillUnmount() {
this.destroyPlayer();
}
setupPlayer() {
const player = new Player(this.playerDiv.current, this.playerConfig);
UIFactory.buildDefaultUI(player);
player.load(this.playerSource).then(() => {
this.setState({
...this.state,
player
});
console.log('Successfully loaded source');
}, () => {
console.log('Error while loading source');
});
}
destroyPlayer() {
if (this.state.player != null) {
this.state.player.destroy();
this.setState({
...this.state,
player: null
});
}
}
render() {
return <div id='player' ref={this.playerDiv}/>;
}
}
export default BitmovinPlayer;