Skip to content

Commit

Permalink
update artplayer-tool-thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
zhw2590582 committed Jan 11, 2022
1 parent 1aa83e1 commit 0dcf2ac
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
1 change: 0 additions & 1 deletion docs/assets/example/thumbnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var thumbnail = new ArtplayerToolThumbnail({
fileInput: $artplayer,
number: 60, // 数量
width: 160, // 宽度
height: 90, // 高度
column: 10, // 列数
begin: 0, // 开始
end: NaN, // 结束
Expand Down
7 changes: 3 additions & 4 deletions docs/uncompiled/artplayer-tool-thumbnail.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/uncompiled/artplayer-tool-thumbnail.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions packages/artplayer-tool-thumbnail/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ArtplayerToolThumbnail extends Emitter {

setup(option = {}) {
this.option = Object.assign({}, this.option, option);
const { fileInput, number, width, height, column } = this.option;
const { fileInput, number, width, column } = this.option;

this.errorHandle(fileInput instanceof Element, "The 'fileInput' is not a Element");

Expand All @@ -59,13 +59,12 @@ class ArtplayerToolThumbnail extends Emitter {
this.option.fileInput = newFileInput;
}

['number', 'width', 'height', 'column', 'begin', 'end'].forEach((item) => {
['number', 'width', 'column', 'begin', 'end'].forEach((item) => {
this.errorHandle(typeof this.option[item] === 'number', `The '${item}' is not a number`);
});

this.option.number = clamp(number, 10, 1000);
this.option.width = clamp(width, 10, 1000);
this.option.height = clamp(height, 10, 1000);
this.option.column = clamp(column, 1, 1000);
return this;
}
Expand Down Expand Up @@ -105,7 +104,9 @@ class ArtplayerToolThumbnail extends Emitter {

start() {
if (!this.video.duration) return sleep(1000).then(() => this.start());
const { width, height, number, begin, end } = this.option;
const { width, number, begin, end } = this.option;
const height = (this.video.videoHeight / this.video.videoWidth) * width;
this.option.height = height;
this.option.begin = clamp(begin, 0, this.video.duration);
this.option.end = clamp(end || this.video.duration, begin, this.video.duration);
this.errorHandle(this.option.end > this.option.begin, `End time must be greater than the start time`);
Expand Down

0 comments on commit 0dcf2ac

Please sign in to comment.