selectTime
Select the time state slice from the player store
Pass selectTime to usePlayer to subscribe to time state. Returns undefined if the time feature is not configured.
Pass selectTime to PlayerController 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>
);
}import { createPlayer, MediaElement } from '@videojs/html';
import { videoFeatures } from '@videojs/html/video';
import { selectTime } from '@videojs/core/dom';
const { PlayerController, context } = createPlayer({ features: videoFeatures });
class TimeDisplay extends MediaElement {
#time = new PlayerController(this, context, selectTime);
}API Reference
Parameters
| Parameter | Type | Default | |
|---|---|---|---|
state* | object | — |
Return Value
MediaTimeState | undefined