fix(android): prevent duplicate onVideoEnd callback on prop changes (#4762)

This commit is contained in:
Harang
2025-11-05 20:43:24 +09:00
committed by GitHub
parent a9f752435f
commit 05cd5972c2

View File

@@ -227,6 +227,7 @@ public class ReactExoplayerView extends FrameLayout implements
*/ */
private boolean isSeeking = false; private boolean isSeeking = false;
private long seekPosition = -1; private long seekPosition = -1;
private boolean hasVideoEnded = false;
// Props from React // Props from React
private Source source = new Source(); private Source source = new Source();
@@ -1411,6 +1412,7 @@ public class ReactExoplayerView extends FrameLayout implements
break; break;
case Player.STATE_READY: case Player.STATE_READY:
text += "ready"; text += "ready";
hasVideoEnded = false;
eventEmitter.onReadyForDisplay.invoke(); eventEmitter.onReadyForDisplay.invoke();
onBuffering(false); onBuffering(false);
clearProgressMessageHandler(); // ensure there is no other message clearProgressMessageHandler(); // ensure there is no other message
@@ -1429,7 +1431,10 @@ public class ReactExoplayerView extends FrameLayout implements
case Player.STATE_ENDED: case Player.STATE_ENDED:
text += "ended"; text += "ended";
updateProgress(); updateProgress();
eventEmitter.onVideoEnd.invoke(); if (!hasVideoEnded) {
hasVideoEnded = true;
eventEmitter.onVideoEnd.invoke();
}
onStopPlayback(); onStopPlayback();
setKeepScreenOn(false); setKeepScreenOn(false);
break; break;
@@ -1819,7 +1824,10 @@ public class ReactExoplayerView extends FrameLayout implements
if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION
&& player.getRepeatMode() == Player.REPEAT_MODE_ONE) { && player.getRepeatMode() == Player.REPEAT_MODE_ONE) {
updateProgress(); updateProgress();
eventEmitter.onVideoEnd.invoke(); if (!hasVideoEnded) {
hasVideoEnded = true;
eventEmitter.onVideoEnd.invoke();
}
} }
} }
@@ -2030,6 +2038,7 @@ public class ReactExoplayerView extends FrameLayout implements
} }
if (!isSourceEqual) { if (!isSourceEqual) {
hasVideoEnded = false;
playerNeedsSource = true; playerNeedsSource = true;
initializePlayer(); initializePlayer();
} }