mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-14 08:26:16 -08:00
update
This commit is contained in:
1 parent
dabfb2b8c8
commit
fedbf3b6f7
10 files changed
+1
-480
No files matched your search
@@ -1,6 +1,4 @@
|
||||
import { errorHandle, has, def } from '../utils';
|
||||
import localVideo from './localVideo';
|
||||
import localSubtitle from './localSubtitle';
|
||||
import miniProgressBar from './miniProgressBar';
|
||||
|
||||
export default class Plugins {
|
||||
@@ -14,14 +12,6 @@ export default class Plugins {
|
||||
this.add(miniProgressBar);
|
||||
}
|
||||
|
||||
if (option.localVideo) {
|
||||
this.add(localVideo);
|
||||
}
|
||||
|
||||
if (option.localSubtitle) {
|
||||
this.add(localSubtitle);
|
||||
}
|
||||
|
||||
for (let index = 0; index < option.plugins.length; index++) {
|
||||
this.add(option.plugins[index]);
|
||||
}
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
import { query, append, setStyle, setStyles, errorHandle, getExt } from '../utils';
|
||||
|
||||
export default function localSubtitle(art) {
|
||||
const {
|
||||
events: { proxy },
|
||||
subtitle,
|
||||
setting,
|
||||
i18n,
|
||||
} = art;
|
||||
|
||||
function loadSubtitle(file) {
|
||||
if (file) {
|
||||
const type = getExt(file.name);
|
||||
if (['ass', 'vtt', 'srt'].includes(type)) {
|
||||
subtitle.switch(URL.createObjectURL(file), {
|
||||
name: file.name,
|
||||
ext: type,
|
||||
});
|
||||
art.emit('localSubtitle', file);
|
||||
} else {
|
||||
errorHandle(false, 'Only supports subtitle files in .ass, .vtt and .srt format');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function attach(target) {
|
||||
const $input = append(target, '<input type="file">');
|
||||
setStyle(target, 'position', 'relative');
|
||||
setStyles($input, {
|
||||
position: 'absolute',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
left: '0',
|
||||
top: '0',
|
||||
opacity: '0',
|
||||
});
|
||||
proxy($input, 'change', () => {
|
||||
const file = $input.files[0];
|
||||
loadSubtitle(file);
|
||||
});
|
||||
}
|
||||
|
||||
art.once('ready', () => {
|
||||
setting.add({
|
||||
title: 'Local Subtitle',
|
||||
name: 'localSubtitle',
|
||||
index: 40,
|
||||
html: `
|
||||
<div class="art-setting-header">
|
||||
${i18n.get('Local Subtitle')}
|
||||
</div>
|
||||
<div class="art-setting-upload">
|
||||
<div class="art-upload-btn">${i18n.get('Open')}</div>
|
||||
<div class="art-upload-value"></div>
|
||||
</div>
|
||||
`,
|
||||
mounted: ($setting) => {
|
||||
const $btn = query('.art-upload-btn', $setting);
|
||||
const $value = query('.art-upload-value', $setting);
|
||||
art.on('localSubtitle', (file) => {
|
||||
$value.textContent = file.name;
|
||||
$value.title = file.name;
|
||||
});
|
||||
attach($btn);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
name: 'localSubtitle',
|
||||
attach,
|
||||
};
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
import { append, query, setStyle, setStyles, errorHandle } from '../utils';
|
||||
|
||||
export default function localVideo(art) {
|
||||
const {
|
||||
events: { proxy },
|
||||
template: { $video, $player },
|
||||
option,
|
||||
setting,
|
||||
i18n,
|
||||
} = art;
|
||||
|
||||
function loadVideo(file) {
|
||||
if (file) {
|
||||
const canPlayType = $video.canPlayType(file.type);
|
||||
if (canPlayType === 'maybe' || canPlayType === 'probably') {
|
||||
const url = URL.createObjectURL(file);
|
||||
option.title = file.name;
|
||||
art.switchUrl(url, file.name);
|
||||
art.emit('localVideo', file);
|
||||
} else {
|
||||
errorHandle(false, 'Playback of this file format is not supported');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
proxy($player, 'dragover', (event) => {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
proxy($player, 'drop', (event) => {
|
||||
event.preventDefault();
|
||||
const file = event.dataTransfer.files[0];
|
||||
loadVideo(file);
|
||||
});
|
||||
|
||||
function attach(target) {
|
||||
const $input = append(target, '<input type="file">');
|
||||
setStyle(target, 'position', 'relative');
|
||||
setStyles($input, {
|
||||
position: 'absolute',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
left: '0',
|
||||
top: '0',
|
||||
opacity: '0',
|
||||
});
|
||||
proxy($input, 'change', () => {
|
||||
const file = $input.files[0];
|
||||
loadVideo(file);
|
||||
});
|
||||
}
|
||||
|
||||
art.once('ready', () => {
|
||||
setting.add({
|
||||
title: 'Local Video',
|
||||
name: 'localVideo',
|
||||
index: 30,
|
||||
html: `
|
||||
<div class="art-setting-header">
|
||||
${i18n.get('Local Video')}
|
||||
</div>
|
||||
<div class="art-setting-upload">
|
||||
<div class="art-upload-btn">${i18n.get('Open')}</div>
|
||||
<div class="art-upload-value"></div>
|
||||
</div>
|
||||
`,
|
||||
mounted: ($setting) => {
|
||||
const $btn = query('.art-upload-btn', $setting);
|
||||
const $value = query('.art-upload-value', $setting);
|
||||
art.on('localVideo', (file) => {
|
||||
$value.textContent = file.name;
|
||||
$value.title = file.name;
|
||||
});
|
||||
attach($btn);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
name: 'localVideo',
|
||||
attach,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user