handle play promise
This commit is contained in:
+20
-20
@@ -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 () {
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -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",
|
||||
|
||||
@@ -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
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user