UNPKG

@theoplayer/react-native-ui

Version:

A React Native UI for @theoplayer/react-native

50 lines (49 loc) 1.59 kB
import { Text } from 'react-native'; import React, { useContext } from 'react'; import { PlayerContext } from '../util/PlayerContext'; import { isAtLive, isLiveDuration } from '../util/LiveUtils'; import { formatTime } from '../util/TimeUtils'; import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; /** * A static time label for the `react-native-theoplayer` UI. */ export function StaticTimeLabel(props) { const { style, showDuration, time, duration, seekable } = props; const context = useContext(PlayerContext); // An invalid duration if (showDuration && !isValidDuration(duration)) { return /*#__PURE__*/_jsx(_Fragment, {}); } const isLive = isLiveDuration(duration); const atLive = isAtLive(duration, time, seekable); if (isLive && atLive) { return /*#__PURE__*/_jsx(_Fragment, {}); } const endTime = duration && isFinite(duration) ? duration : seekable && seekable.length > 0 ? seekable[seekable.length - 1].end : NaN; let timeOnLabel = time; if (isLive) { timeOnLabel = -((endTime || 0) - time); } let text; if (showDuration && !isLive) { text = `${formatTime(timeOnLabel, endTime, isLive)} / ${formatTime(endTime)}`; } else { text = formatTime(timeOnLabel, endTime, isLive); } return /*#__PURE__*/_jsx(Text, { style: [context.style.text, { color: context.style.colors.text }, style], children: `${text}` }); } function isValidDuration(duration) { return duration !== undefined && !isNaN(duration) && duration > 0; } //# sourceMappingURL=StaticTimeLabel.js.map