Skip to content

Commit

Permalink
fix FromFileBase loop mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Dec 3, 2024
1 parent 152972a commit 2707c46
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
12 changes: 2 additions & 10 deletions library/src/main/java/com/pedro/library/base/FromFileBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down

0 comments on commit 2707c46

Please sign in to comment.