Since React uses lifecycle methods and the virtual dom how can I detect when my video has finished playing. I found another question like this on stackoverflow that suggested to use componentWillUnmount but there's no point at which I remove the video from the dom, so componentWillUnmount won't get fired...
How can I detect when video finished playing react?
Video React package provide Player component to show video player and also provide onEnded on player to detect video end or not. import { Player } from "video-react"; import "video-react/dist/video-react.
To show current time and update the seconds in real time with React Native, we can use the setInterval function to update the time every second. to call setInterval with a callback that calls setTime with new Date(). toLocaleString() to set time to the current date time string.
React (also known as React. js or ReactJS) is a free and open-source front-end JavaScript library for building user interfaces based on UI components. It is maintained by Meta (formerly Facebook) and a community of individual developers and companies.
You could also use the onEnded
media event on the video element. This feature has been supported since 2015; it's much easier to work with and can be used in functional components.
const myCallback = () => (console.log('Video has ended'));
<video autoplay onEnded={() => myCallback()}>
<source src={[yourVideoURL]} type="video/mp4" />
</video>
Also make sure loop
is not true
on the video element, because then, the onEnded event will never be fired.
More information here: https://reactjs.org/blog/2015/09/10/react-v0.14-rc1.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With