From d71707f22009929032348acf2cdc34a2caa54afa Mon Sep 17 00:00:00 2001 From: Julian Cable Date: Wed, 11 Jan 2017 23:11:32 +0000 Subject: [PATCH] Make constructor clearer --- .../text/SubtitleDecoderFactory.java | 7 +++--- .../exoplayer2/text/ssa/SSADecoder.java | 22 ++++++++----------- .../exoplayer2/text/ssa/SSASubtitle.java | 4 +++- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java b/library/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java index e21d4404ad..b953f10067 100644 --- a/library/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java +++ b/library/src/main/java/com/google/android/exoplayer2/text/SubtitleDecoderFactory.java @@ -25,6 +25,7 @@ import com.google.android.exoplayer2.text.webvtt.Mp4WebvttDecoder; import com.google.android.exoplayer2.text.webvtt.WebvttDecoder; import com.google.android.exoplayer2.util.MimeTypes; +import java.io.UnsupportedEncodingException; import java.util.List; import static android.R.attr.initialKeyguardLayout; @@ -83,9 +84,9 @@ public interface SubtitleDecoderFactory { } if(clazz == SSADecoder.class) { byte[] header = format.initializationData.get(1); - byte[] dialogueFormat = format.initializationData.get(0); - return clazz.asSubclass(SubtitleDecoder.class).getConstructor(byte[].class, byte[].class) - .newInstance(header, dialogueFormat); + String dlgfmt = new String(format.initializationData.get(0), "UTF-8"); + return clazz.asSubclass(SubtitleDecoder.class).getConstructor(byte[].class, String.class) + .newInstance(header, dlgfmt); } if (clazz == Cea608Decoder.class) { return clazz.asSubclass(SubtitleDecoder.class).getConstructor(String.class, Integer.TYPE) diff --git a/library/src/main/java/com/google/android/exoplayer2/text/ssa/SSADecoder.java b/library/src/main/java/com/google/android/exoplayer2/text/ssa/SSADecoder.java index 4b160f8a00..2453e00238 100644 --- a/library/src/main/java/com/google/android/exoplayer2/text/ssa/SSADecoder.java +++ b/library/src/main/java/com/google/android/exoplayer2/text/ssa/SSADecoder.java @@ -70,20 +70,16 @@ public class SSADecoder extends SimpleSubtitleDecoder { private String[] dialogueFormat = null; private String[] styleFormat = null; private Map styles = new HashMap<>(); + private final static long _1e6 = 1000000; public SSADecoder() { super("SSADecoder"); } - public SSADecoder(byte[] header, byte[] dialogueFormatBytes) { + public SSADecoder(byte[] header, String dlgfmt) { super("SSADecoder"); decodeHeader(header, header.length); - try { - dialogueFormat = parseKeys(new String(dialogueFormatBytes, "UTF-8")); - } - catch (UnsupportedEncodingException e) { - // can't happen? - } + dialogueFormat = parseKeys(dlgfmt); } /** @@ -203,7 +199,7 @@ public class SSADecoder extends SimpleSubtitleDecoder { s.append(","); long endUs = durationUs; // + blockTimeUs if (endUs == C.TIME_UNSET) { - endUs = 2000000; // 2 second default duration + endUs = 2*_1e6; // 2 second default duration } s.append(SSADecoder.formatTimeCode(endUs)); s.append(","); @@ -213,13 +209,13 @@ public class SSADecoder extends SimpleSubtitleDecoder { } public static String formatTimeCode(long tc_us) { - long seconds = tc_us / 1000000; - long us = tc_us - 1000000*seconds; + long seconds = tc_us / _1e6; + long us = tc_us - _1e6*seconds; long minutes = seconds / 60; seconds -= 60 * minutes; long hours = minutes / 60; minutes -= 60*hours; - double sec = seconds + ((float)us)/1000000.0; + double sec = seconds + ((float)us)/_1e6; return String.format(Locale.US, "%01d:%02d:%06.3f", hours, minutes, sec); } @@ -228,8 +224,8 @@ public class SSADecoder extends SimpleSubtitleDecoder { long hours = Long.parseLong(p[0]); long minutes = Long.parseLong(p[1]); float seconds = Float.parseFloat(p[2]); - float us = 1000000*seconds; + float us = _1e6*seconds; long lus = ((long)us); - return lus + 1000000 * (60 * (minutes + 60 * hours)); + return lus + _1e6 * (60 * (minutes + 60 * hours)); } } diff --git a/library/src/main/java/com/google/android/exoplayer2/text/ssa/SSASubtitle.java b/library/src/main/java/com/google/android/exoplayer2/text/ssa/SSASubtitle.java index 1a8ad728f8..b619a201fa 100644 --- a/library/src/main/java/com/google/android/exoplayer2/text/ssa/SSASubtitle.java +++ b/library/src/main/java/com/google/android/exoplayer2/text/ssa/SSASubtitle.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Map; import static android.R.attr.start; +import static android.os.Build.VERSION_CODES.N; /** * Created by cablej01 on 26/12/2016. @@ -92,6 +93,7 @@ public class SSASubtitle implements Subtitle { int layer = Integer.parseInt(ev.get("layer")); String effect = ev.get("effect"); String text = ev.get("text").replaceAll("\\\\N", "\n"); + text = text.replaceAll("\\\\n", "\n"); String simpleText = text.replaceAll("\\{[^{]*\\}", ""); //Cue cue = new SSACue(text, style, layer, effect); Cue cue = new Cue(simpleText); @@ -99,7 +101,7 @@ public class SSASubtitle implements Subtitle { cueTimesUs.add(start); cues.add(cue); // add null cue to remove this cue after it's duration - long end = SSADecoder.parseTimecode(ev.get("end")); + long end = 10*SSADecoder.parseTimecode(ev.get("end")); cueTimesUs.add(end); cues.add(null); }