diff --git a/library/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaPeriod.java b/library/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaPeriod.java index 2888f267ce..1ad448bd12 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaPeriod.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/SingleSampleMediaPeriod.java @@ -41,7 +41,7 @@ import java.util.Arrays; /** * The initial size of the allocation used to hold the sample data. */ - private static final int INITIAL_SAMPLE_SIZE = 1; + private static final int INITIAL_SAMPLE_SIZE = 1024; private final Uri uri; private final DataSource.Factory dataSourceFactory; @@ -71,7 +71,6 @@ import java.util.Arrays; tracks = new TrackGroupArray(new TrackGroup(format)); sampleStreams = new ArrayList<>(); loader = new Loader("Loader:SingleSampleMediaPeriod"); - sampleData = new byte[INITIAL_SAMPLE_SIZE]; } public void release() { @@ -269,7 +268,9 @@ import java.util.Arrays; int result = 0; while (result != C.RESULT_END_OF_INPUT) { sampleSize += result; - if (sampleSize == sampleData.length) { + if (sampleData == null) { + sampleData = new byte[INITIAL_SAMPLE_SIZE]; + } else if (sampleSize == sampleData.length) { sampleData = Arrays.copyOf(sampleData, sampleData.length * 2); } result = dataSource.read(sampleData, sampleSize, sampleData.length - sampleSize); diff --git a/library/src/main/java/com/google/android/exoplayer2/text/TextRenderer.java b/library/src/main/java/com/google/android/exoplayer2/text/TextRenderer.java index d69a2339a1..e28363f9e4 100644 --- a/library/src/main/java/com/google/android/exoplayer2/text/TextRenderer.java +++ b/library/src/main/java/com/google/android/exoplayer2/text/TextRenderer.java @@ -160,21 +160,27 @@ public final class TextRenderer extends BaseRenderer implements Callback { } } - if (nextSubtitle != null && nextSubtitle.timeUs <= positionUs) { - // Advance to the next subtitle. Sync the next event index and trigger an update. - if (subtitle != null) { - subtitle.release(); + if (nextSubtitle != null) { + if (nextSubtitle.isEndOfStream()) { + if (!textRendererNeedsUpdate && getNextEventTime() == Long.MAX_VALUE) { + if (subtitle != null) { + subtitle.release(); + subtitle = null; + } + nextSubtitle.release(); + nextSubtitle = null; + outputStreamEnded = true; + } + } else if (nextSubtitle.timeUs <= positionUs) { + // Advance to the next subtitle. Sync the next event index and trigger an update. + if (subtitle != null) { + subtitle.release(); + } + subtitle = nextSubtitle; + nextSubtitle = null; + nextSubtitleEventIndex = subtitle.getNextEventTimeIndex(positionUs); + textRendererNeedsUpdate = true; } - subtitle = nextSubtitle; - nextSubtitle = null; - if (subtitle.isEndOfStream()) { - outputStreamEnded = true; - subtitle.release(); - subtitle = null; - return; - } - nextSubtitleEventIndex = subtitle.getNextEventTimeIndex(positionUs); - textRendererNeedsUpdate = true; } if (textRendererNeedsUpdate) {