Skip to content

feat: add onLoop event - #2047

Open
yoreljenkins wants to merge 1 commit into
cookpete:masterfrom
yoreljenkins:feature/on-loop
Open

feat: add onLoop event#2047
yoreljenkins wants to merge 1 commit into
cookpete:masterfrom
yoreljenkins:feature/on-loop

Conversation

@yoreljenkins

@yoreljenkins yoreljenkins commented Aug 25, 2026

Copy link
Copy Markdown

Adds an onLoop callback that fires when native looping restarts the media.

ended is deliberately never fired when the loop attribute is set, so there is currently no way to know a video has looped. onLoop detects the restart from timeupdate, the current time jumping from the end of the media back to the start which works for every player in the library, not just <video>. It is gated on the element's loop property, so nothing fires unless native looping is on.

<ReactPlayer src={src} loop onLoop={(event, iteration) => console.log('loop', iteration)} />

iteration counts completed loops from 1 and resets when a new src loads. onTimeUpdate still passes through untouched, and onLoop is filtered out of the props forwarded to the underlying element.

The one false positive is seeking from within the last ~0.5s back to the first ~0.5s while looping, indistinguishable from a real loop at the event level. A backward seek anywhere else is correctly ignored.

Tests cover loop counting, backward-seek rejection, loop off, and onTimeUpdate pass-through.

@yoreljenkins
yoreljenkins marked this pull request as ready for review August 25, 2026 14:23
@yoreljenkins

Copy link
Copy Markdown
Author

@cookpete This PR introduces the onLoop event! Please check if this is an implementation that you would like. I have a lot of usecases for this event, mostly tracking based.

@guid-ooo

Copy link
Copy Markdown

this is the only feature i'm missing from this package!! would be great if this could be added. @cookpete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants