-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvideojs_ABdm.js
124 lines (110 loc) · 3.63 KB
/
videojs_ABdm.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
videojs.plugin('ABP', ABPinit);
function ABPinit(){
function Danmu(ele){
///////////////////////////////////////////
///Prepare the html element for the plugin.
///////////////////////////////////////////
_this=this;
this.danmuDiv = document.createElement('div');
this.danmuDiv.className = 'vjs-danmu';
ele.el().insertBefore(this.danmuDiv,ele.el().getElementsByClassName('vjs-poster')[0]);
this.danmuShowControl = document.createElement('div');
this.danmuShowControl.className = 'vjs-danmu-control vjs-menu-button vjs-control';
this.danmuShowControlContent = document.createElement('span');
this.danmuShowControlContent.className = 'glyphicon glyphicon-eye-open';
this.danmuShowControl.appendChild(this.danmuShowControlContent);
ele.el().getElementsByClassName('vjs-control-bar')[0].appendChild(this.danmuShowControl);
///////////////////////////////////////////
//Bind CommentManager.
///////////////////////////////////////////
if(typeof CommentManager !== "undefined"){
this.cmManager = new CommentManager(this.danmuDiv);
this.cmManager.display = true;
this.cmManager.init();
this.cmManager.clear();
//Bind control to video.
var video=ele.el().children[0];
var lastPosition = 0;
video.addEventListener("progress", function(){
if(lastPosition == video.currentTime){
video.hasStalled = true;
_this.cmManager.stopTimer();
}else
lastPosition = video.currentTime;
});
video.addEventListener("timeupdate", function(){
if(_this.cmManager.display === false) return;
if(video.hasStalled){
_this.cmManager.startTimer();
video.hasStalled = false;
}
_this.cmManager.time(Math.floor(video.currentTime * 1000));
});
video.addEventListener("play", function(){
_this.cmManager.startTimer();
});
video.addEventListener("pause", function(){
_this.cmManager.stopTimer();
});
video.addEventListener("waiting", function(){
_this.cmManager.stopTimer();
});
video.addEventListener("playing",function(){
_this.cmManager.startTimer();
});
video.addEventListener("seeked",function(){
_this.cmManager.clear();
});
if(window){
window.addEventListener("resize", function(){
_this.cmManager.setBounds();
});
}
//Bind Control to button
this.danmuShowControl.addEventListener("click", function(){
if(_this.cmManager.display==true){
_this.cmManager.display=false;
_this.cmManager.clear();
_this.danmuShowControlContent.setAttribute("class","glyphicon glyphicon-eye-close");
}else{
_this.cmManager.display=true;
_this.danmuShowControlContent.setAttribute("class","glyphicon glyphicon-eye-open");
}
});
//Create Load function
this.load = function(url,callback){
if(callback == null)
callback = function(){return;};
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
var cm = this.cmManager;
var cmvideo = video;
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
if(navigator.appName == 'Microsoft Internet Explorer'){
var f = new ActiveXObject("Microsoft.XMLDOM");
f.async = false;
f.loadXML(xmlhttp.responseText);
cm.load(BilibiliParser(f));
cm.seek(cmvideo.currentTime*1000);
callback(true);
}else{
cm.seek(cmvideo.currentTime*1000);
cm.load(BilibiliParser(xmlhttp.responseXML));
callback(true);
}
}else
callback(false);
}
}
}
return this;
}
this.danmu = new Danmu(this);
}