Replies: 2 comments 6 replies
-
I would be interested in some outside perspective on syncing this up with a DB, I use MongoDB myself. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for sharing your solution @Apezdr! We have a storage solution coming in the next release which will handle this for you and a few other player settings such as volume and captions: // Coming soon!
<MediaPlayer storageKey="my-player" /> If you want to handle this yourself, here's an alternative solution: function WithPlaybackTracking({ videoURL }) {
const canPlay = useMediaState('canPlay'),
remote = useMediaRemote();
useEffect(() => {
if (!canPlay) return;
const savedTime = parseFloat(localStorage.getItem(videoURL));
if (!isNaN(savedTime)) remote.seek(savedTime);
}, [remote, canPlay, videoURL]);
useEffect(() => {
if (!player || !canPlay) return;
return player.subscribe(({ currentTime }) => {
localStorage.setItem(videoURL, currentTime + '');
});
}, [player, canPlay, videoURL]);
} |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've written up a component to include inside of the
MediaProvider
to track the amount of the video the user has watched. I wanted to share it with the community because it took me a good little while to get it sorted (embarrassingly so..); if this helps you feel free to share the love!In my
WithPlaybackTracker
component:Beta Was this translation helpful? Give feedback.
All reactions