Skip to content

Commit

Permalink
Refactor artplayerPluginLibass to use ES6 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
zhw2590582 committed Nov 26, 2023
1 parent 4360c1e commit b2bffa8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 113 deletions.
72 changes: 1 addition & 71 deletions docs/assets/example/libass.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,9 @@
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
poster: '/assets/sample/poster.jpg',
volume: 0.5,
isLive: false,
muted: false,
autoplay: false,
pip: true,
autoSize: true,
autoMini: true,
screenshot: true,
setting: true,
loop: true,
flip: true,
playbackRate: true,
aspectRatio: true,
fullscreen: true,
fullscreenWeb: true,
subtitleOffset: true,
miniProgressBar: true,
mutex: true,
backdrop: true,
playsInline: true,
autoPlayback: true,
airplay: true,
theme: '#23ade5',
lang: navigator.language.toLowerCase(),
moreVideoAttr: {
crossOrigin: 'anonymous',
},
settings: [
{
width: 200,
html: 'Subtitle',
tooltip: 'Bilingual',
icon: '<img width="22" heigth="22" src="/assets/img/subtitle.svg">',
selector: [
{
html: 'Display',
tooltip: 'Show',
switch: true,
onSwitch: function (item) {
item.tooltip = item.switch ? 'Hide' : 'Show';
art.subtitle.show = !item.switch;
return !item.switch;
},
},
{
html: 'Style Test',
url: '/assets/sample/style-test.ass',
},
{
default: true,
html: 'Bilingual',
url: '/assets/sample/subtitle.ass',
},
{
html: 'subtitle.srt',
url: '/assets/sample/subtitle.srt',
},
],
onSelect: function (item) {
art.subtitle.switch(item.url, {
name: item.html,
});
return item.html;
},
},
],
subtitle: {
url: '/assets/sample/subtitle.ass',
style: {
color: '#48aff0',
fontSize: '16px',
},
url: '/assets/sample/style-test.ass',
},
plugins: [
artplayerPluginLibass({
Expand Down
19 changes: 4 additions & 15 deletions docs/uncompiled/artplayer-plugin-libass/index.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-plugin-libass/index.js.map

Large diffs are not rendered by default.

31 changes: 5 additions & 26 deletions packages/artplayer-plugin-libass/src/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
import LibassAdapter from './adapter'

function checkVersion(art) {
const {
version,
utils: { errorHandle },
} = art.constructor
const arr = version.split('.').map(Number)
const major = arr[0]
const minor = arr[1] / 100
errorHandle(
major + minor >= 5,
`Artplayer.js@${version} is not compatible the artplayerPluginLibass@${artplayerPluginLibass.version}. Please update it to version [email protected]`,
)
}
import LibassAdapter from './adapter';

export default function artplayerPluginLibass(option) {
return (art) => {
checkVersion(art)

let adapter = new LibassAdapter(art, option)

const adapter = new LibassAdapter(art, option);
return {
name: 'artplayerPluginLibass',
libass: adapter.libass,
Expand All @@ -29,14 +12,10 @@ export default function artplayerPluginLibass(option) {
show: adapter.show.bind(adapter),
hide: adapter.hide.bind(adapter),
destroy: adapter.destroy.bind(adapter),
}
}
};
};
}

artplayerPluginLibass.env = process.env.NODE_ENV
artplayerPluginLibass.version = process.env.APP_VER
artplayerPluginLibass.build = process.env.BUILD_DATE

if (typeof window !== 'undefined') {
window['artplayerPluginLibass'] = artplayerPluginLibass
window['artplayerPluginLibass'] = artplayerPluginLibass;
}

1 comment on commit b2bffa8

@vercel
Copy link

@vercel vercel bot commented on b2bffa8 Nov 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.