Skip to content

Commit

Permalink
fix fromfile video without audio and setloop can be used before prepare
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Oct 27, 2023
1 parent 7a11f20 commit 2e1311e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app/src/main/res/layout/activity_from_file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2e1311e

Please sign in to comment.