fix error in reading empty danmaku list

This commit is contained in:
DIYgod 2018-01-12 00:45:09 +08:00
parent 6f61076345
commit 6524114f05
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
6 changed files with 36 additions and 31 deletions

View File

@ -149,26 +149,26 @@ function initPlayers () {
// }
// });
// window.dp6 = new DPlayer({
// container: document.getElementById('dplayer6'),
// preload: 'none',
// live: true,
// danmaku: true,
// apiBackend: {
// read: function (endpoint, callback) {
// console.log('假装 WebSocket 连接成功');
// callback();
// },
// send: function (endpoint, danmakuData, callback) {
// console.log('假装通过 WebSocket 发送数据', danmakuData);
// callback();
// }
// },
// video: {
// url: 'https://moeplayer.b0.upaiyun.com/dplayer/hls/hikarunara.m3u8',
// type: 'hls'
// }
// });
window.dp6 = new DPlayer({
container: document.getElementById('dplayer6'),
preload: 'none',
live: true,
danmaku: true,
apiBackend: {
read: function (endpoint, callback) {
console.log('假装 WebSocket 连接成功');
callback();
},
send: function (endpoint, danmakuData, callback) {
console.log('假装通过 WebSocket 发送数据', danmakuData);
callback();
}
},
video: {
url: 'https://moeplayer.b0.upaiyun.com/dplayer/hls/hikarunara.m3u8',
type: 'hls'
}
});
}
function clearPlayers () {

View File

@ -56,7 +56,7 @@
<h2 id="live">Live</h2>
<div class="example">
<button class="btn" onclick="drawDanmaku()">假装收到 WebSocket 弹幕</button>
<button class="btn" onclick="dp6.danmaku.draw({text: '假装收到 WebSocket 弹幕', color: '#fff', type: 'right'})">假装收到 WebSocket 弹幕</button>
<div id="dplayer6"></div>
</div>

2
dist/DPlayer.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "dplayer",
"version": "1.19.0",
"version": "1.19.1",
"description": "Wow, such a lovely HTML5 danmaku video player",
"main": "dist/DPlayer.min.js",
"style": "dist/DPlayer.min.css",

View File

@ -68,6 +68,7 @@ class Danmaku {
}
else {
const typeMap = ['right', 'top', 'bottom'];
if (data) {
results[i] = data.map((item) => ({
time: item[0],
type: typeMap[item[1]],
@ -76,6 +77,10 @@ class Danmaku {
text: item[4]
}));
}
else {
results[i] = [];
}
}
if (readCount === endpoints.length) {
return callback(results);
}