From ed8c6d9debe19a8ae4eea04ca29cba4b5c0bf763 Mon Sep 17 00:00:00 2001 From: pedro Date: Wed, 1 Nov 2023 20:07:04 +0100 Subject: [PATCH] fix end of file error when startStream after finish video --- .../pedro/encoder/input/decoder/BaseDecoder.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/encoder/src/main/java/com/pedro/encoder/input/decoder/BaseDecoder.java b/encoder/src/main/java/com/pedro/encoder/input/decoder/BaseDecoder.java index f47500cb1..6f137e13e 100644 --- a/encoder/src/main/java/com/pedro/encoder/input/decoder/BaseDecoder.java +++ b/encoder/src/main/java/com/pedro/encoder/input/decoder/BaseDecoder.java @@ -229,6 +229,7 @@ public double getTime() { private void decode() { if (startTs == 0) { + moveTo(0); //make sure that we are on the start startTs = System.nanoTime() / 1000; } long sleepTime = 0; @@ -287,13 +288,15 @@ private void decode() { boolean render = decodeOutput(output); codec.releaseOutputBuffer(outIndex, render && bufferInfo.size != 0); boolean finished = extractor.getSampleTime() < 0; - if (finished && loopMode) { - moveTo(0); - looped = true; + if (finished) { + if (loopMode) { + moveTo(0); + looped = true; + } else { + Log.i(TAG, "end of file"); + finished(); + } } - } else if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0 || sampleSize < 0) { - Log.i(TAG, "end of file"); - finished(); } } }