diff --git a/app/src/main/res/layout/activity_from_file.xml b/app/src/main/res/layout/activity_from_file.xml index 40a859c70..7732ada7e 100644 --- a/app/src/main/res/layout/activity_from_file.xml +++ b/app/src/main/res/layout/activity_from_file.xml @@ -84,8 +84,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tv_file" - android:layout_above="@+id/b_select_file" - android:layout_centerHorizontal="true" + app:layout_constraintBottom_toTopOf="@id/b_select_file" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" android:textColor="@color/appColor" android:layout_margin="10dp" /> 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 38dabc823..f47500cb1 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 @@ -255,13 +255,17 @@ private void decode() { } else { input = codec.getInputBuffers()[inIndex]; } + if (input == null) continue; sampleSize = extractor.readSampleData(input, 0); long ts = System.nanoTime() / 1000 - startTs; long extractorTs = extractor.getSampleTime(); accumulativeTs += extractorTs - lastExtractorTs; lastExtractorTs = extractor.getSampleTime(); - if (accumulativeTs > ts) sleepTime = accumulativeTs - ts; + + if (accumulativeTs > ts) sleepTime = (accumulativeTs - ts) / 1000; + else sleepTime = 0; + if (sampleSize < 0) { if (!loopMode) { codec.queueInputBuffer(inIndex, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM); @@ -273,7 +277,7 @@ private void decode() { } int outIndex = codec.dequeueOutputBuffer(bufferInfo, 10000); if (outIndex >= 0) { - if (!sleep(sleepTime / 1000)) return; + if (!sleep(sleepTime)) return; ByteBuffer output; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { output = codec.getOutputBuffer(outIndex); 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 a6749b47d..b7e435c97 100644 --- a/library/src/main/java/com/pedro/library/base/FromFileBase.java +++ b/library/src/main/java/com/pedro/library/base/FromFileBase.java @@ -485,8 +485,8 @@ public void stopStream() { * @param loopMode true in loop, false stop stream when video finish. */ public void setLoopMode(boolean loopMode) { - if (videoEnabled) videoDecoder.setLoopMode(loopMode); - if (audioEnabled) audioDecoder.setLoopMode(loopMode); + videoDecoder.setLoopMode(loopMode); + audioDecoder.setLoopMode(loopMode); } public void reSyncFile() {