feat: support line break for subtitle (#396)

Fix subtitle bug
This commit is contained in:
DIYgod 2019-06-06 16:34:26 +08:00 committed by GitHub
commit 405817404d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 8 deletions

View File

@ -18,14 +18,12 @@ class Subtitle {
track.oncuechange = () => {
const cue = track.activeCues[0];
this.container.innerHTML = '';
if (cue) {
this.container.innerHTML = '';
const p = document.createElement('p');
p.appendChild(cue.getCueAsHTML());
this.container.appendChild(p);
}
else {
this.container.innerHTML = '';
const template = document.createElement('div');
template.appendChild(cue.getCueAsHTML());
const trackHtml = template.innerHTML.split(/\r?\n/).map(item => `<p>${item}</p>`).join('');
this.container.innerHTML = trackHtml;
}
this.events.trigger('subtitle_change');
};
@ -52,4 +50,4 @@ class Subtitle {
}
}
export default Subtitle;
export default Subtitle;