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 9b10944b2..e97bd5aae 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 @@ -93,6 +93,16 @@ public void stop() { extractor.release(); } + public void reset(Surface surface) { + boolean wasRunning = running; + stopDecoder(!wasRunning); + moveTo(0); + prepare(surface); + if (wasRunning) { + start(); + } + } + protected boolean prepare(Surface surface) { try { codec = MediaCodec.createDecoderByType(mime); @@ -185,14 +195,8 @@ private void decode() { synchronized (sync) { if (pause.get()) continue; if (looped) { - double time = getTime(); - if (time > 0) { - moveTo(0); - continue; - } else { - decoderInterface.onLoop(); - looped = false; - } + decoderInterface.onLoop(); + looped = false; } int inIndex = codec.dequeueInputBuffer(10000); int sampleSize; @@ -231,7 +235,6 @@ private void decode() { codec.releaseOutputBuffer(outIndex, render && bufferInfo.size != 0); if (finished) { if (loopMode) { - moveTo(0); looped = true; } else { Log.i(TAG, "end of file"); diff --git a/library/src/main/java/com/pedro/library/base/FromFileBase.java b/library/src/main/java/com/pedro/library/base/FromFileBase.java index 000220522..0ae12bfff 100644 --- a/library/src/main/java/com/pedro/library/base/FromFileBase.java +++ b/library/src/main/java/com/pedro/library/base/FromFileBase.java @@ -767,18 +767,10 @@ public void onVideoFormat(@NonNull MediaFormat mediaFormat) { private final DecoderInterface decoderInterface = new DecoderInterface() { - private int trackFinished = 0; - @Override public void onLoop() { - int maxTracks = 0; - if (audioEnabled) maxTracks++; - if (videoEnabled) maxTracks++; - trackFinished++; - if (trackFinished >= maxTracks) { - reSyncFile(); - trackFinished = 0; - } + videoDecoder.reset(glInterface.getSurface()); + audioDecoder.reset(null); } };