-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
42 lines (34 loc) · 1.05 KB
/
index.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
import {HTML5Video, Log, Events} from 'clappr'
export default class DashDashjsPlayback extends HTML5Video {
name() {return 'dash_dashjs_playback'}
constructor(options) {
super(options)
this._embedScript()
}
_embedScript() {
if (!window.Dash) {
var script = document.createElement('script')
script.setAttribute("type", "text/javascript")
script.setAttribute("async", "async")
script.setAttribute("src", "https://sslplayers-vh.akamaihd.net/dash.js/latest/dash.all.js")
script.onload = () => this._setup()
script.onerror = (e) => this._onError(e)
document.body.appendChild(script)
} else {
this._setup()
}
}
_onError(error) {
Log.error(error)
}
_setup() {
var player = new MediaPlayer(new Dash.di.DashContext())
player.startup()
player.attachView(this.el)
player.attachSource(this.options.src)
}
}
DashDashjsPlayback.canPlay = function(resource, mimeType) {
var resourceParts = resource.split('?')[0].match(/.*\.(.*)$/) || []
return "mpd" === resourceParts[1]
}