mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 16:11:20 -08:00
修改字幕乱码
This commit is contained in:
1 parent
ed009f9d4d
commit
92686dfcb6
13 files changed
+207
-162
No files matched your search
@@ -148,6 +148,7 @@ export default class Artplayer extends Emitter {
|
||||
subtitle: {
|
||||
url: '',
|
||||
style: {},
|
||||
encoding: 'utf-8',
|
||||
bilingual: false,
|
||||
},
|
||||
moreVideoAttr: {
|
||||
|
||||
@@ -52,10 +52,10 @@ export default function localSubtitle(art) {
|
||||
<div class="art-upload-value"></div>
|
||||
</div>
|
||||
`,
|
||||
mounted: $setting => {
|
||||
mounted: ($setting) => {
|
||||
const $btn = query('.art-upload-btn', $setting);
|
||||
const $value = query('.art-upload-value', $setting);
|
||||
art.on('localSubtitle', file => {
|
||||
art.on('localSubtitle', (file) => {
|
||||
$value.textContent = file.name;
|
||||
$value.title = file.name;
|
||||
});
|
||||
|
||||
@@ -90,6 +90,7 @@ export default {
|
||||
subtitle: {
|
||||
url: 'string',
|
||||
style: 'object',
|
||||
encoding: 'string',
|
||||
bilingual: 'boolean',
|
||||
},
|
||||
moreVideoAttr: 'object',
|
||||
|
||||
@@ -15,11 +15,17 @@
|
||||
p {
|
||||
word-break: break-all;
|
||||
height: fit-content;
|
||||
margin: 10px 0 0;
|
||||
margin: 5px 0 0;
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.art-bilingual {
|
||||
p:nth-child(2) {
|
||||
font-size: 0.6em;
|
||||
}
|
||||
}
|
||||
|
||||
&.art-subtitle-show {
|
||||
.art-subtitle {
|
||||
display: block;
|
||||
|
||||
@@ -35,6 +35,14 @@ export default class Subtitle extends Component {
|
||||
return this.textTrack.activeCues[0];
|
||||
}
|
||||
|
||||
get encoding() {
|
||||
return this.art.option.subtitle.encoding;
|
||||
}
|
||||
|
||||
set encoding(value) {
|
||||
this.art.option.subtitle.encoding = value;
|
||||
}
|
||||
|
||||
style(key, value) {
|
||||
const { $subtitle } = this.art.template;
|
||||
if (typeof key === 'object') {
|
||||
@@ -55,9 +63,9 @@ export default class Subtitle extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
switch(url, name, ext) {
|
||||
switch(url, name, ext, encoding) {
|
||||
const { i18n, notice } = this.art;
|
||||
return this.init(url, ext).then((subUrl) => {
|
||||
return this.init(url, ext, encoding).then((subUrl) => {
|
||||
if (name) {
|
||||
notice.show = `${i18n.get('Switch subtitle')}: ${name}`;
|
||||
}
|
||||
@@ -66,10 +74,11 @@ export default class Subtitle extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
init(url, ext) {
|
||||
init(url, ext, encoding) {
|
||||
const {
|
||||
notice,
|
||||
events: { proxy },
|
||||
option: { subtitle },
|
||||
template: { $subtitle, $video, $track },
|
||||
} = this.art;
|
||||
|
||||
@@ -83,8 +92,11 @@ export default class Subtitle extends Component {
|
||||
}
|
||||
|
||||
return fetch(url)
|
||||
.then((response) => response.text())
|
||||
.then((text) => {
|
||||
.then((response) => response.arrayBuffer())
|
||||
.then((buffer) => {
|
||||
const decoder = new TextDecoder(encoding || subtitle.encoding);
|
||||
const text = decoder.decode(buffer);
|
||||
|
||||
this.art.emit('subtitleLoad', url);
|
||||
switch (ext || getExt(url)) {
|
||||
case 'srt':
|
||||
|
||||
Reference in new issue
Block a user