manifest-controller.js
1.33 KB
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
(function(window) {
var M3U8 = window.videojs.hls.M3U8;
var M3U8Parser = window.videojs.hls.M3U8Parser;
var M3U8TagTypes = window.videojs.hls.m3u8TagType;
window.videojs.hls.ManifestController = function(){
var self = this;
var parser;
var data;
var onDataCallback;
var onErrorCallback;
var onUpdateCallback;
self.loadManifest = function ( manifestUrl, onDataCallback, onErrorCallback, onUpdateCallback ) {
self.onDataCallback = onDataCallback;
self.onErrorCallback = onErrorCallback;
self.onUpdateCallback = onUpdateCallback;
vjs.get(manifestUrl, self.onManifestLoadComplete, self.onManifestLoadError);
};
self.parseManifest = function ( dataAsString ) {
self.parser = new M3U8Parser();
self.data = self.parser.parse( dataAsString );
return self.data;
};
self.onManifestLoadComplete = function(response) {
var output = self.parseManifest(response);
if(self.onDataCallback != undefined)
{
self.onDataCallback(output);
}
};
self.onManifestLoadError = function(err) {
if(err)
{
console.log(err.message);
}
if(self.onErrorCallback != undefined)
{
onErrorCallback((err != undefined) ? err : null);
}
};
}
})(this);
/*
mc = new window.videojs.hls.ManifestController('myM3u8.m3u8', {
onData: function(){},
onError: function(){},
onUpdate: function(){}
});
*/