Skip to content

Commit

Permalink
fix checking loading bug
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jul 11, 2017
1 parent 99b5eca commit 07ef15b
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 48 deletions.
2 changes: 1 addition & 1 deletion dist/DPlayer.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/DPlayer.min.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dplayer",
"version": "1.4.2",
"version": "1.4.3",
"description": "Wow, such a lovely HTML5 danmaku video player",
"main": "dist/DPlayer.min.js",
"style": "dist/DPlayer.min.css",
Expand Down Expand Up @@ -31,13 +31,13 @@
"devDependencies": {
"autoprefixer": "^7.1.1",
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-loader": "^7.1.1",
"babel-preset-es2015": "^6.24.1",
"css-loader": "^0.28.0",
"eslint": "^4.1.0",
"eslint-loader": "^1.7.1",
"eslint-loader": "^1.9.0",
"exports-loader": "^0.6.4",
"extract-text-webpack-plugin": "^2.1.0",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.1",
"node-sass": "^4.5.0",
"postcss-loader": "^2.0.5",
Expand All @@ -46,7 +46,7 @@
"style-loader": "^0.18.1",
"template-string-optimize-loader": "^2.2.3",
"url-loader": "^0.5.7",
"webpack": "^3.0.0",
"webpack": "^3.1.0",
"webpack-dev-server": "^2.4.5"
}
}
41 changes: 34 additions & 7 deletions src/DPlayer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
console.log('\n %c DPlayer 1.4.2 %c http://dplayer.js.org \n\n', 'color: #fadfa3; background: #030307; padding:5px 0;', 'background: #fadfa3; padding:5px 0;');
console.log('\n %c DPlayer 1.4.3 %c http://dplayer.js.org \n\n', 'color: #fadfa3; background: #030307; padding:5px 0;', 'background: #fadfa3; padding:5px 0;');

require('./DPlayer.scss');
const utils = require('./utils.js');
Expand Down Expand Up @@ -126,24 +126,43 @@ class DPlayer {
let bufferingDetected = false;
this.danmakuTime = false;
this.playedTime = false;
this.animationFrame = () => {
if (this.playedTime) {
window.requestAnimationFrame = (() =>
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) {
window.setTimeout(callback, 1000 / 60);
}
)();

const setCheckLoadingTime = () => {
this.checkLoading = setInterval(() => {
// whether the video is buffering
currentPlayPos = this.video.currentTime();
if (!bufferingDetected
&& currentPlayPos < lastPlayPos + 0.001
&& currentPlayPos < lastPlayPos + 0.01
&& !this.video.attr('paused')) {
this.element.classList.add('dplayer-loading');
bufferingDetected = true;
}
if (bufferingDetected
&& currentPlayPos > lastPlayPos + 0.001
&& currentPlayPos > lastPlayPos + 0.01
&& !this.video.attr('paused')) {
this.element.classList.remove('dplayer-loading');
bufferingDetected = false;
}
lastPlayPos = currentPlayPos;
}, 100);
};

const clearCheckLoadingTime = () => {
clearInterval(this.checkLoading);
};

this.animationFrame = () => {
if (this.playedTime) {
this.updateBar('played', this.video.currentTime() / this.video.duration, 'width');
this.element.getElementsByClassName('dplayer-ptime')[0].innerHTML = utils.secondToTime(this.video.currentTime());
this.trigger('playing');
Expand All @@ -157,26 +176,34 @@ class DPlayer {
}
this.pushDanmaku(danmakus);
}
requestAnimationFrame(this.animationFrame);
window.requestAnimationFrame(this.animationFrame);
};
requestAnimationFrame(this.animationFrame);
window.requestAnimationFrame(this.animationFrame);

this.setTime = (type) => {
if (!type) {
this.danmakuTime = true;
this.playedTime = true;
setCheckLoadingTime();
}
else {
this[`${type}Time`] = true;
if (type === 'played') {
setCheckLoadingTime();
}
}
};
this.clearTime = (type) => {
if (!type) {
this.danmakuTime = false;
this.playedTime = false;
clearCheckLoadingTime();
}
else {
this[`${type}Time`] = false;
if (type === 'played') {
clearCheckLoadingTime();
}
}
};

Expand Down
107 changes: 73 additions & 34 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ajv-keywords@^2.0.0:
version "2.1.0"
resolved "http://registry.npm.taobao.org/ajv-keywords/download/ajv-keywords-2.1.0.tgz#a296e17f7bfae7c1ce4f7e0de53d29cb32162df0"

ajv@^4.11.2, ajv@^4.7.0, ajv@^4.9.1:
ajv@^4.7.0, ajv@^4.9.1:
version "4.11.8"
resolved "http://registry.npm.taobao.org/ajv/download/ajv-4.11.8.tgz#82ffb02b29e662ae53bdc20af15947706739c536"
dependencies:
Expand Down Expand Up @@ -191,7 +191,7 @@ async@^1.5.2:
version "1.5.2"
resolved "http://registry.npm.taobao.org/async/download/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"

async@^2.1.2, async@^2.1.5:
async@^2.1.2, async@^2.1.5, async@^2.4.1:
version "2.4.1"
resolved "http://registry.npm.taobao.org/async/download/async-2.4.1.tgz#62a56b279c98a11d0987096a01cc3eeb8eb7bbd7"
dependencies:
Expand Down Expand Up @@ -351,11 +351,11 @@ babel-helpers@^6.24.1:
babel-runtime "^6.22.0"
babel-template "^6.24.1"

babel-loader@^7.0.0:
version "7.0.0"
resolved "http://registry.npm.taobao.org/babel-loader/download/babel-loader-7.0.0.tgz#2e43a66bee1fff4470533d0402c8a4532fafbaf7"
babel-loader@^7.1.1:
version "7.1.1"
resolved "http://registry.npm.taobao.org/babel-loader/download/babel-loader-7.1.1.tgz#b87134c8b12e3e4c2a94e0546085bc680a2b8488"
dependencies:
find-cache-dir "^0.1.1"
find-cache-dir "^1.0.0"
loader-utils "^1.0.2"
mkdirp "^0.5.1"

Expand Down Expand Up @@ -1363,9 +1363,9 @@ encodeurl@~1.0.1:
version "1.0.1"
resolved "http://registry.npm.taobao.org/encodeurl/download/encodeurl-1.0.1.tgz#79e3d58655346909fe6f0f45a5de68103b294d20"

enhanced-resolve@^3.0.0:
version "3.1.0"
resolved "http://registry.npm.taobao.org/enhanced-resolve/download/enhanced-resolve-3.1.0.tgz#9f4b626f577245edcf4b2ad83d86e17f4f421dec"
enhanced-resolve@^3.3.0:
version "3.3.0"
resolved "http://registry.npm.taobao.org/enhanced-resolve/download/enhanced-resolve-3.3.0.tgz#950964ecc7f0332a42321b673b38dc8ff15535b3"
dependencies:
graceful-fs "^4.1.2"
memory-fs "^0.4.0"
Expand Down Expand Up @@ -1464,11 +1464,10 @@ escope@^3.6.0:
esrecurse "^4.1.0"
estraverse "^4.1.1"

eslint-loader@^1.7.1:
version "1.7.1"
resolved "http://registry.npm.taobao.org/eslint-loader/download/eslint-loader-1.7.1.tgz#50b158dd6272dcefb97e984254837f81a5802ce0"
eslint-loader@^1.9.0:
version "1.9.0"
resolved "http://registry.npm.taobao.org/eslint-loader/download/eslint-loader-1.9.0.tgz#7e1be9feddca328d3dcfaef1ad49d5beffe83a13"
dependencies:
find-cache-dir "^0.1.1"
loader-fs-cache "^1.0.0"
loader-utils "^1.0.2"
object-assign "^4.0.1"
Expand Down Expand Up @@ -1665,14 +1664,14 @@ extglob@^0.3.1:
dependencies:
is-extglob "^1.0.0"

extract-text-webpack-plugin@^2.1.0:
version "2.1.0"
resolved "http://registry.npm.taobao.org/extract-text-webpack-plugin/download/extract-text-webpack-plugin-2.1.0.tgz#69315b885f876dbf96d3819f6a9f1cca7aebf159"
extract-text-webpack-plugin@^3.0.0:
version "3.0.0"
resolved "http://registry.npm.taobao.org/extract-text-webpack-plugin/download/extract-text-webpack-plugin-3.0.0.tgz#90caa7907bc449f335005e3ac7532b41b00de612"
dependencies:
ajv "^4.11.2"
async "^2.1.2"
loader-utils "^1.0.2"
webpack-sources "^0.1.0"
async "^2.4.1"
loader-utils "^1.1.0"
schema-utils "^0.3.0"
webpack-sources "^1.0.1"

[email protected]:
version "1.0.2"
Expand Down Expand Up @@ -1755,13 +1754,27 @@ find-cache-dir@^0.1.1:
mkdirp "^0.5.1"
pkg-dir "^1.0.0"

find-cache-dir@^1.0.0:
version "1.0.0"
resolved "http://registry.npm.taobao.org/find-cache-dir/download/find-cache-dir-1.0.0.tgz#9288e3e9e3cc3748717d39eade17cf71fc30ee6f"
dependencies:
commondir "^1.0.1"
make-dir "^1.0.0"
pkg-dir "^2.0.0"

find-up@^1.0.0:
version "1.1.2"
resolved "http://registry.npm.taobao.org/find-up/download/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f"
dependencies:
path-exists "^2.0.0"
pinkie-promise "^2.0.0"

find-up@^2.1.0:
version "2.1.0"
resolved "http://registry.npm.taobao.org/find-up/download/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7"
dependencies:
locate-path "^2.0.0"

flat-cache@^1.2.1:
version "1.2.2"
resolved "http://registry.npm.taobao.org/flat-cache/download/flat-cache-1.2.2.tgz#fa86714e72c21db88601761ecf2f555d1abc6b96"
Expand Down Expand Up @@ -2513,6 +2526,13 @@ loader-utils@^1.0.1, loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.x
emojis-list "^2.0.0"
json5 "^0.5.0"

locate-path@^2.0.0:
version "2.0.0"
resolved "http://registry.npm.taobao.org/locate-path/download/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
dependencies:
p-locate "^2.0.0"
path-exists "^3.0.0"

lodash.assign@^4.2.0:
version "4.2.0"
resolved "http://registry.npm.taobao.org/lodash.assign/download/lodash.assign-4.2.0.tgz#0d99f3ccd7a6d261d19bdaeb9245005d285808e7"
Expand Down Expand Up @@ -2577,6 +2597,12 @@ macaddress@^0.2.8:
version "0.2.8"
resolved "http://registry.npm.taobao.org/macaddress/download/macaddress-0.2.8.tgz#5904dc537c39ec6dbefeae902327135fa8511f12"

make-dir@^1.0.0:
version "1.0.0"
resolved "http://registry.npm.taobao.org/make-dir/download/make-dir-1.0.0.tgz#97a011751e91dd87cfadef58832ebb04936de978"
dependencies:
pify "^2.3.0"

map-obj@^1.0.0, map-obj@^1.0.1:
version "1.0.1"
resolved "http://registry.npm.taobao.org/map-obj/download/map-obj-1.0.1.tgz#d933ceb9205d82bdcf4886f6742bdc2b4dea146d"
Expand Down Expand Up @@ -2960,6 +2986,16 @@ osenv@0, osenv@^0.1.4:
os-homedir "^1.0.0"
os-tmpdir "^1.0.0"

p-limit@^1.1.0:
version "1.1.0"
resolved "http://registry.npm.taobao.org/p-limit/download/p-limit-1.1.0.tgz#b07ff2d9a5d88bec806035895a2bab66a27988bc"

p-locate@^2.0.0:
version "2.0.0"
resolved "http://registry.npm.taobao.org/p-locate/download/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43"
dependencies:
p-limit "^1.1.0"

pako@~0.2.0:
version "0.2.9"
resolved "http://registry.npm.taobao.org/pako/download/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"
Expand Down Expand Up @@ -3003,6 +3039,10 @@ path-exists@^2.0.0:
dependencies:
pinkie-promise "^2.0.0"

path-exists@^3.0.0:
version "3.0.0"
resolved "http://registry.npm.taobao.org/path-exists/download/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"

path-is-absolute@^1.0.0:
version "1.0.1"
resolved "http://registry.npm.taobao.org/path-is-absolute/download/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
Expand Down Expand Up @@ -3057,6 +3097,12 @@ pkg-dir@^1.0.0:
dependencies:
find-up "^1.0.0"

pkg-dir@^2.0.0:
version "2.0.0"
resolved "http://registry.npm.taobao.org/pkg-dir/download/pkg-dir-2.0.0.tgz#f6d5d1109e19d63edf428e0bd57e12777615334b"
dependencies:
find-up "^2.1.0"

pluralize@^4.0.0:
version "4.0.0"
resolved "http://registry.npm.taobao.org/pluralize/download/pluralize-4.0.0.tgz#59b708c1c0190a2f692f1c7618c446b052fd1762"
Expand Down Expand Up @@ -3847,7 +3893,7 @@ sort-keys@^1.0.0:
dependencies:
is-plain-obj "^1.0.0"

source-list-map@^0.1.7, source-list-map@~0.1.7:
source-list-map@^0.1.7:
version "0.1.8"
resolved "http://registry.npm.taobao.org/source-list-map/download/source-list-map-0.1.8.tgz#c550b2ab5427f6b3f21f5afead88c4f5587b2106"

Expand Down Expand Up @@ -4183,7 +4229,7 @@ uglify-to-browserify@~1.0.0:
version "1.0.2"
resolved "http://registry.npm.taobao.org/uglify-to-browserify/download/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7"

uglifyjs-webpack-plugin@^0.4.4:
uglifyjs-webpack-plugin@^0.4.6:
version "0.4.6"
resolved "http://registry.npm.taobao.org/uglifyjs-webpack-plugin/download/uglifyjs-webpack-plugin-0.4.6.tgz#b951f4abb6bd617e66f63eb891498e391763e309"
dependencies:
Expand Down Expand Up @@ -4335,30 +4381,23 @@ webpack-dev-server@^2.4.5:
webpack-dev-middleware "^1.10.2"
yargs "^6.0.0"

webpack-sources@^0.1.0:
version "0.1.5"
resolved "http://registry.npm.taobao.org/webpack-sources/download/webpack-sources-0.1.5.tgz#aa1f3abf0f0d74db7111c40e500b84f966640750"
dependencies:
source-list-map "~0.1.7"
source-map "~0.5.3"

webpack-sources@^1.0.1:
version "1.0.1"
resolved "http://registry.npm.taobao.org/webpack-sources/download/webpack-sources-1.0.1.tgz#c7356436a4d13123be2e2426a05d1dad9cbe65cf"
dependencies:
source-list-map "^2.0.0"
source-map "~0.5.3"

webpack@^3.0.0:
version "3.0.0"
resolved "http://registry.npm.taobao.org/webpack/download/webpack-3.0.0.tgz#ee9bcebf21247f7153cb410168cab45e3a59d4d7"
webpack@^3.1.0:
version "3.1.0"
resolved "http://registry.npm.taobao.org/webpack/download/webpack-3.1.0.tgz#ac0675e500db835f9ab2369d29ba096f51ad0731"
dependencies:
acorn "^5.0.0"
acorn-dynamic-import "^2.0.0"
ajv "^5.1.5"
ajv-keywords "^2.0.0"
async "^2.1.2"
enhanced-resolve "^3.0.0"
enhanced-resolve "^3.3.0"
escope "^3.6.0"
interpret "^1.0.0"
json-loader "^0.5.4"
Expand All @@ -4371,7 +4410,7 @@ webpack@^3.0.0:
source-map "^0.5.3"
supports-color "^3.1.0"
tapable "~0.2.5"
uglifyjs-webpack-plugin "^0.4.4"
uglifyjs-webpack-plugin "^0.4.6"
watchpack "^1.3.1"
webpack-sources "^1.0.1"
yargs "^6.0.0"
Expand Down

0 comments on commit 07ef15b

Please sign in to comment.