Commit 440aeea6 by Julian Cable

working but still with stateful decoder. Sample subtitle <span> encoder but this…

working but still with stateful decoder. Sample subtitle <span> encoder but this doesn't seem to be how webvtt does it so not being used.
parent 141568ab
...@@ -1112,6 +1112,7 @@ public final class MatroskaExtractor implements Extractor { ...@@ -1112,6 +1112,7 @@ public final class MatroskaExtractor implements Extractor {
private void writeSSASample(Track track) { private void writeSSASample(Track track) {
long startUs = 0; // blockTimeUs long startUs = 0; // blockTimeUs
startUs = blockTimeUs;
StringBuffer s = new StringBuffer(); StringBuffer s = new StringBuffer();
s.append("Dialogue: "); s.append("Dialogue: ");
s.append(SSADecoder.formatTimeCode(startUs)); s.append(SSADecoder.formatTimeCode(startUs));
......
...@@ -3,6 +3,7 @@ package com.google.android.exoplayer2.text.ssa; ...@@ -3,6 +3,7 @@ package com.google.android.exoplayer2.text.ssa;
import android.util.Log; import android.util.Log;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.SimpleSubtitleDecoder;
import com.google.android.exoplayer2.text.Subtitle; import com.google.android.exoplayer2.text.Subtitle;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
...@@ -12,6 +13,7 @@ import java.util.List; ...@@ -12,6 +13,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import static android.R.attr.start; import static android.R.attr.start;
import static android.R.attr.text;
import static android.os.Build.VERSION_CODES.N; import static android.os.Build.VERSION_CODES.N;
/** /**
...@@ -63,40 +65,68 @@ public class SSASubtitle implements Subtitle { ...@@ -63,40 +65,68 @@ public class SSASubtitle implements Subtitle {
} }
} }
protected void addEvent(Map<String,String> ev, Map<String,Style> styles) { private void addifNonZero(StringBuffer s, String key, String m) {
int marginL = 0; if(!m.equals("")) {
String m = ev.get("marginl"); int n = Integer.parseInt(m);
if(!m.equals("")) if(n>0) {
marginL = Integer.parseInt(m); s.append(String.format("%s:%d; ", key, n));
int marginR = 0; }
m = ev.get("marginr"); }
if(!m.equals("")) }
marginR = Integer.parseInt(m);
int marginV = 0; protected void addEvent(Map<String,String> ev) {
m = ev.get("marginv"); StringBuffer text = new StringBuffer();
if(!m.equals("")) StringBuffer s = new StringBuffer();
marginV = Integer.parseInt(m); addifNonZero(s, "marginL", ev.get("marginl"));
String styleName = ev.get("style"); addifNonZero(s, "marginR", ev.get("marginr"));
Style style = styles.get(styleName); addifNonZero(s, "marginV", ev.get("marginv"));
if(marginL!=0 || marginR!=0 || marginV !=0) { addifNonZero(s, "layer", ev.get("layer"));
style = new Style(style); String m = ev.get("effect");
if(!m.equals("")) {
s.append(String.format("effect:%s;", m));
} }
if(marginL!=0) { if(s.length()>0) {
style.setMarginL(marginL); m = s.toString();
s = new StringBuffer();
s.append(" style=\"");
s.append(m);
s.append("\"");
} }
if(marginR!=0) { if(!ev.get("style").equals("Default")){
style.setMarginR(marginR); s.append(" class=\"");
s.append(ev.get("style"));
s.append("\"");
} }
if(marginV!=0) { String textContent = ev.get("text").replaceAll("\\\\N", "\n");
style.setMarginV(marginV); textContent = textContent.replaceAll("\\\\n", "\n");
String simpleText = textContent.replaceAll("\\{[^{]*\\}", "");
Cue cue = null;
if(!s.toString().trim().equals("")) {
text.append("<span");
text.append(s);
text.append(">");
text.append(simpleText);
text.append("</span>");
cue = new Cue(text.toString());
} }
int layer = Integer.parseInt(ev.get("layer")); else {
String effect = ev.get("effect"); cue = new Cue(simpleText);
String text = ev.get("text").replaceAll("\\\\N", "\n"); }
text = text.replaceAll("\\\\n", "\n"); long start = SSADecoder.parseTimecode(ev.get("start"));
String simpleText = text.replaceAll("\\{[^{]*\\}", ""); cueTimesUs.add(start);
//Cue cue = new SSACue(text, style, layer, effect); cues.add(cue);
Cue cue = new Cue(simpleText); // add null cue to remove this cue after it's duration
long end = SSADecoder.parseTimecode(ev.get("end"));
cueTimesUs.add(end);
cues.add(null);
}
protected void addEvent(Map<String,String> ev, Map<String,Style> styles) {
Style style = styles.get(ev.get("style"));
// TODO clone style and override margins from fields
String textContent = ev.get("text").replaceAll("\\\\N", "\n");
textContent = textContent.replaceAll("\\\\n", "\n");
Cue cue = new SSACue(textContent, style, Integer.parseInt(ev.get("layer")), ev.get("effect"));
long start = SSADecoder.parseTimecode(ev.get("start")); long start = SSADecoder.parseTimecode(ev.get("start"));
cueTimesUs.add(start); cueTimesUs.add(start);
cues.add(cue); cues.add(cue);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment