Explorar o código

Fix subtitle bug

Fix display problems with multiple lines of subtitles.

修复字幕存在多行的情况,`cue.getCueAsHTML() `本身并没有`innerHTML`方法,所以处理了一下。
Harvey Zack %!s(int64=7) %!d(string=hai) anos
pai
achega
c09070601a
Modificáronse 1 ficheiros con 6 adicións e 8 borrados
  1. 6 8
      src/js/subtitle.js

+ 6 - 8
src/js/subtitle.js

@@ -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.insertAdjacentHTML('beforeend', trackHtml);
                 }
                 this.events.trigger('subtitle_change');
             };
@@ -52,4 +50,4 @@ class Subtitle {
     }
 }
 
-export default Subtitle;
+export default Subtitle;