forked from leandromoreira/clappr-dash-dashjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (53 loc) · 2.14 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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", "//cdnjs.cloudflare.com/ajax/libs/dashjs/2.3.0/dash.all.min.js")
// "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 ccdiv, player = dashjs.MediaPlayer().create();
this._player = player;
player.getDebug().setLogToBrowserConsole(false);
player.initialize(this.el,this.options.src,true);
ccdiv=document.createElement('div');
this.el.parentNode.appendChild(ccdiv);
player.attachTTMLRenderingDiv(ccdiv);
if (typeof this.options.dashjsProtectionData !== "undefined") {
player.getProtectionController().setProtectionData(this.options.dashjsProtectionData);
}
}
// mimic portions of shaka interface
get textTracks() {return this._player && this._player.getTracksFor('text')}
get audioTracks() {return this._player && this._player.getTracksFor('audio')}
get videoTracks() {return this._player && this._player.getTracksFor('video')}
selectTrack(track) {
this._player.setCurrentTrack(track)
}
}
DashDashjsPlayback.canPlay = function(resource, mimeType) {
var resourceParts = resource.split('?')[0].match(/.*\.(.*)$/) || []
return "mpd" === resourceParts[1]
|| mimeType === "application/dash+xml"
|| mimeType === "video/vnd.mpeg.dash.mpd"
// /* hack... still CORS issues with videoplayback... */ ||resourceParts[1].indexOf("//manifest.")>=0
// /* hack... */ ||resourceParts[1].indexOf(".ism/manifest")>=0
// /* hack... */ ||resourceParts[1].indexOf("/mpds/")>=0
}