FrameworkStyle

selectTime

Select the time state slice from the player store

Import

import { selectTime } from '@videojs/core/dom';

Usage

Pass selectTime to usePlayer (React) or PlayerController (HTML) to subscribe to time state. Returns undefined if the time feature is not configured.

The returned state includes currentTime, duration, and the seek action method.

import { usePlayer } from '@videojs/react';
import { selectTime } from '@videojs/core/dom';

function TimeDisplay() {
  const time = usePlayer(selectTime);
  if (!time) return null;

  return (
    <span>
      {Math.floor(time.currentTime)} / {Math.floor(time.duration)}
    </span>
  );
}

API Reference

Parameters

Parameter Type Default
state* {}

Return Value

MediaTimeState | undefined

VideoJS