From c3adffb1ec7c5f13a9db19c6f80e3fbf89835884 Mon Sep 17 00:00:00 2001 From: sinchang Date: Sat, 24 Jun 2017 11:20:06 +0800 Subject: [PATCH] update switchVideo method --- src/DPlayer.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/DPlayer.js b/src/DPlayer.js index 89b1866..5c6a2c2 100644 --- a/src/DPlayer.js +++ b/src/DPlayer.js @@ -12,7 +12,7 @@ const isMobile = /mobile/i.test(window.navigator.userAgent); let index = 0; class DPlayer { - + /** * DPlayer constructor function * @@ -868,10 +868,10 @@ class DPlayer { ++readCount; if (err) { if (err.response) { - this.notice(err.response.msg); + this.notice(err.response.msg); } else { - this.notice('Request was unsuccessful: ' + err.status); + this.notice('Request was unsuccessful: ' + err.status); } results[i] = []; } @@ -1022,7 +1022,8 @@ class DPlayer { switchVideo (video, danmaku) { this.video.src = video.url; this.video.poster = video.pic ? video.pic : ''; - this.video.currentTime = 0; + this.video.current.setAttribute('poster', this.video.poster); + this.video.current.setAttribute('src', this.video.src); this.pause(); if (danmaku) { this.dan = []; @@ -1170,7 +1171,7 @@ class DPlayer { this.switchingQuality = true; this.quality = this.option.video.quality[index]; this.element.getElementsByClassName('dplayer-quality-icon')[0].innerHTML = this.quality.name; - + this.video.pause(); const videoHTML = html.video(false, null, this.option.screenshot, 'auto', this.quality.url); const videoEle = new DOMParser().parseFromString(videoHTML, 'text/html').body.firstChild; @@ -1189,7 +1190,7 @@ class DPlayer { } parent.removeChild(this.prevVideo.current); this.video.current.classList.add('dplayer-video-current'); - this.video.play(); + this.video.play(); this.prevVideo = null; this.notice(`${this.tran('Switched to')} ${this.quality.name} ${this.tran('quality')}`); this.switchingQuality = false;