handle play promise

This commit is contained in:
DIYgod
2018-01-18 00:24:15 +08:00
parent 6524114f05
commit cda90989b2
6 changed files with 35 additions and 38 deletions
+20 -20
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 () {
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "dplayer",
"version": "1.19.1",
"version": "1.20.0",
"description": "Wow, such a lovely HTML5 danmaku video player",
"main": "dist/DPlayer.min.js",
"style": "dist/DPlayer.min.css",
-5
View File
@@ -1,12 +1,7 @@
/* global DPLAYER_VERSION GIT_HASH */
import defaultApiBackend from './api.js';
import utils from './utils';
export default (options) => {
// compatibility: some mobile browsers don't suppose autoplay
if (utils.isMobile) {
options.autoplay = false;
}
// default options
const defaultOption = {
+12 -10
View File
@@ -83,7 +83,7 @@ class DPlayer {
this.template.danmakuLoading.style.display = 'none';
// autoplay
if (this.options.autoplay && !utils.isMobile) {
if (this.options.autoplay) {
this.play();
}
else if (utils.isMobile) {
@@ -132,14 +132,8 @@ class DPlayer {
this.initVideo(this.video, this.quality && this.quality.type || this.options.video.type);
if (!this.danmaku) {
// autoplay
if (this.options.autoplay && !utils.isMobile) {
this.play();
}
else if (utils.isMobile) {
this.pause();
}
if (!this.danmaku && this.options.autoplay) {
this.play();
}
index++;
@@ -181,7 +175,15 @@ class DPlayer {
this.template.playButton.innerHTML = this.icons.get('pause');
this.video.play();
const playedPromise = this.video.play();
if (playedPromise) {
playedPromise.
catch(() => {
this.pause();
}).
then(() => {
});
}
this.time.enable();
this.container.classList.add('dplayer-playing');
if (this.danmaku) {