mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 08:01:20 -08:00
初始化截图工具
This commit is contained in:
1 parent
73f6cd7493
commit
3396a741dd
5 files changed
+424
-11
No files matched your search
@@ -1,11 +1,61 @@
|
||||
import './index.scss';
|
||||
|
||||
function errorHandle(condition, msg) {
|
||||
if (!condition) {
|
||||
throw new Error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
class ArtplayerToolThumbnail {
|
||||
constructor(el) {
|
||||
this.el = el;
|
||||
console.log(this);
|
||||
constructor(option) {
|
||||
if (option.fileInput) {
|
||||
errorHandle(
|
||||
option.fileInput.tagName === 'INPUT' && option.fileInput.type === 'file',
|
||||
'This fileInput is not a file input',
|
||||
);
|
||||
}
|
||||
|
||||
if (option.videoElement) {
|
||||
errorHandle(option.fileInput.tagName === 'VIDEO', 'This videoElement is not a video element');
|
||||
}
|
||||
|
||||
if (option.callbackVideoUrl) {
|
||||
errorHandle(typeof option.callbackVideoUrl === 'function', 'This callbackVideoUrl is not a function');
|
||||
}
|
||||
|
||||
if (option.callbackThumbnailUrl) {
|
||||
errorHandle(
|
||||
typeof option.callbackThumbnailUrl === 'function',
|
||||
'This callbackThumbnailUrl is not a function',
|
||||
);
|
||||
}
|
||||
|
||||
this.option = option;
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
const fileType = ['video/mp4', 'video/ogg', 'video/webm'];
|
||||
this.option.fileInput.addEventListener('change', () => {
|
||||
const file = this.option.fileInput.files[0];
|
||||
if (file) {
|
||||
errorHandle(fileType.includes(file.type), `Only file types are supported: ${fileType.toString()}`);
|
||||
const videoUrl = URL.createObjectURL(file);
|
||||
this.videoUrl = videoUrl;
|
||||
if (this.option.callbackVideoUrl) {
|
||||
this.option.callbackVideoUrl(videoUrl);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setup(option = {}) {
|
||||
this.option = {
|
||||
...this.option,
|
||||
...option,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
window.ArtplayerToolThumbnail = ArtplayerToolThumbnail;
|
||||
export default ArtplayerToolThumbnail;
|
||||
export default ArtplayerToolThumbnail;
|
||||
Reference in new issue
Block a user