Only save media position on pause or dispose, not every timeupdate, for performance reasons.

This commit is contained in:
Jeffrey Fisher 2020-04-30 21:31:40 -07:00 committed by Sean Yesmunt
parent 3b7bba5ba3
commit 7ea9c1c199

View file

@ -106,10 +106,6 @@ function VideoViewer(props: Props) {
setIsEndededEmbed(false);
}
function onPause() {
setIsPlaying(false);
}
const onPlayerReady = useCallback(
(player: Player) => {
if (!embedded) {
@ -144,7 +140,10 @@ function VideoViewer(props: Props) {
player.on('tracking:firstplay', doTrackingFirstPlay);
player.on('ended', onEnded);
player.on('play', onPlay);
player.on('pause', onPause);
player.on('pause', () => {
setIsPlaying(false);
savePosition(uri, player.currentTime());
});
player.on('volumechange', () => {
if (player && player.volume() !== volume) {
changeVolume(player.volume());
@ -157,7 +156,7 @@ function VideoViewer(props: Props) {
if (position) {
player.currentTime(position);
}
player.on('timeupdate', () => savePosition(uri, player.currentTime()));
player.on('dispose', () => savePosition(uri, player.currentTime()));
},
[uri]
);