Files
ArtPlayer/packages/artplayer-plugin-ass/src/index.js
T
2020-11-24 15:48:49 +08:00

33 lines
933 B
JavaScript

import ASS from 'assjs';
import './style.scss';
function artplayerPluginAss(url) {
return (art) => {
let ass = null;
fetch(url)
.then((res) => res.text())
.then((text) => {
const { $video, $subtitle } = art.template;
$subtitle.classList.add('artplayer-plugin-ass');
art.once('ready', () => {
ass = new ASS(text, $video, {
container: $subtitle,
resampling: 'video_width',
});
ass.resize();
art.emit('artplayerPluginAss', ass);
art.on('resize', () => ass.resize());
art.on('destroy', () => ass.destroy());
});
});
return {
name: 'artplayerPluginAss',
ass,
};
};
}
export default artplayerPluginAss;