-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEryaDanmaku.js
199 lines (171 loc) · 5.97 KB
/
EryaDanmaku.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
function addStyle(url) {
var container = document.getElementsByTagName("head")[0];
var style = document.createElement("link");
style.rel = "stylesheet";
style.type = "text/css";
//style.media = "screen";
style.href = url;
container.appendChild(style);
}
function addScript(url) {
var container = document.getElementsByTagName("head")[0];
var script = document.createElement('script');
script.src = url;
script.type = "text/javascript";
container.appendChild(script);
}
addScript("https://cn.avoscloud.com/scripts/lib/av-0.3.4.min.js");
/* CommentCoreLibrary (//github.com/jabbany/CommentCoreLibrary) - Licensed under the MIT License */
addScript("https://rawgit.com/jabbany/CommentCoreLibrary/master/build/CommentCoreLibrary.js");
addStyle("https://rawgit.com/jabbany/CommentCoreLibrary/master/build/style.css");
/* artDialog */
addScript("https://rawgit.com/SUSTC/EryaDanmaku/master/jquery.artDialog.min.js");
addStyle("https://rawgit.com/SUSTC/EryaDanmaku/master/simple.css");
addScript("https://rawgit.com/SUSTC/EryaDanmaku/master/ColorPicker.js");
addScript("https://rawgit.com/SUSTC/EryaDanmaku/master/Danmaku.js");
addStyle("https://rawgit.com/SUSTC/EryaDanmaku/master/ui.css");
window.onblur = function () {};
$('#eryaPlayer').prepend('<div class="erya-danmaku abp" id="player">'
+ '<div id="c-region" style="display:none;">640x480</div>'
+ '<div id="commentCanvas" class="container"></div>'
+ '</div>');
$('#eryaPlayer').append(
'<div class="danmakubar">' +
' <label>弹幕:</label>' +
' <div class="lefttools"><div class="color_select" id="danmaku-fontcolor" title="文字颜色"></div></div>' +
' <select id="danmaku-fontsize">' +
' <option value="12">非常小</option>' +
' <option value="16">特小</option>' +
' <option value="18">小</option>' +
' <option value="25" selected>中</option>' +
' <option value="36">大</option>' +
' <option value="45">很大</option>' +
' <option value="64">特别大</option>' +
' </select>' +
' <select id="danmaku-mode">' +
' <option value="1" selected>顶端滚动</option>' +
' <option value="4">底端渐隐</option>' +
' <option value="5">顶端渐隐</option>' +
' <option value="6">逆向弹幕</option>' +
' </select>' +
' <input id="id_danmaku" type="text" onkeydown="if(event.keyCode==13) danmaku.post();" />' +
' <input id="danmaku-post" type="button" class="btn btn-small" value="发送" onclick="danmaku.post()" />' +
' <input id="danmaku-hide" type="button" class="btn btn-small" value="隐藏弹幕" onclick="danmaku.dohide()" />' +
' <input id="danmaku-stage-hide" type="button" class="btn btn-small" value="X" />' +
' <li id="danmaku-tips"></li>' +
'</div>');
var danmaku = null;
var edanmaku = null;
var EryaDanmaku = function(danmaku) {
//var flashVars = $("#eryaPlayer").getPlayer().children.namedItem("flashvars").value;
//var conf = JSON.parse(unescape(flashVars.split("&")[3]).substr(6));
//var videoId = conf.currVideoInfo.videoId;
//var flashVars = conf;
var episodeId = cur_video;
var stage_hide_btn = $('#danmaku-stage-hide');
var eryadanmaku = {
episodeId: episodeId
};
eryadanmaku.setEpisode = function(id, callback) {
danmaku.stop();
var videoId = $("#videoId").val();
this.videoId = videoId;
this.episodeId = id;
danmaku.load(videoId, callback);
};
stage_hide_btn.click(function () {
if (stage_hide_btn.val() == 'X') {
stage_hide_btn.val('V');
$('.erya-danmaku').hide();
} else {
stage_hide_btn.val('X');
$('.erya-danmaku').show();
}
});
//Constructed
return eryadanmaku;
};
function AVOSParser(results) {
var data = [];
for (var i = 0; i < results.length; i++) {
var object = results[i];
var color = '#' + parseInt(object.get('color')).toString(16);
data[i] = {
'text': object.get('text'),
'mode': object.get('mode'),
'stime': object.get('stime'),
'size': object.get('size'),
'color': color
};
}
return data;
}
//defer(EryaDanmaku);
function initDanmaku() {
//初始化 AVOS Cloud
AV.initialize("9bfuau87qmvf42xobes7vg7f16kikk1gpgisvb36225mfwld", "1ah2yr74jdwksdep2i4wq0gy18sg01lkqt40epeuqhkde3kv");
var elplayer = $('#eryaPlayer');
var player = elplayer.getPlayer();
//player.getPlaySecond();
//player.playMovie();
var avDanmaku = AV.Object.extend("danmaku");
Danmaku.prototype.loader = function (videoId, callback) {
//reload
var that = this;
var query = new AV.Query(avDanmaku);
query.equalTo("videoId", videoId);
console.log('videoId', videoId);
query.find({
success: function(results) {
that.cm.load(AVOSParser(results));
callback();
},
error: function(err) {
callback(err);
}
});
};
Danmaku.prototype.postdata = function (data) {
var that = this;
var av_danmaku = new avDanmaku();
data.videoId = this.ssid;
av_danmaku.save(data, {
success: function(av_danmaku) {
that.posttips(true);
},
error: function(av_danmaku, err) {
that.posttips(false);
}
});
};
danmaku = new Danmaku($('#eryaPlayer'), $('.danmakubar'), function () {
return player.getPlaySecond() * 1000;
});
edanmaku = EryaDanmaku(danmaku);
function checkPlayState(err) {
if (err) {
return;
}
var playState = player.getPlayState();
if (playState == 2) {
danmaku.stop();
} else if (playState == 1) {
danmaku.resume();
}
}
elplayer.bind('onPlay', function (e, proTime) {
danmaku.resume();
});
elplayer.bind('onPause', function (e, proTime) {
danmaku.stop();
});
elplayer.bind('onMovieDrag', function (e, startTime, endTime, data) {
checkPlayState();
});
elplayer.bind('onStart', function (e, index, data) {
edanmaku.setEpisode(index, checkPlayState);
});
edanmaku.setEpisode(currIndex, checkPlayState);
ep=$("#eryaPlayer");setInterval(function(){ if(ep.getPlayState()==4) goPlay(cur_video+1);}, 1000);
}
setTimeout(initDanmaku, 5000);