Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import { forwardRef, useRef, useImperativeHandle, Ref } from "react";
|
||||
import { t as i18nT } from "i18next";
|
||||
|
||||
export interface RefAudioOrVideo {
|
||||
media: HTMLAudioElement | HTMLVideoElement | null;
|
||||
}
|
||||
|
||||
export type MediaCaptionTrack = {
|
||||
src?: string;
|
||||
srcLang?: string;
|
||||
label?: string;
|
||||
default?: boolean;
|
||||
};
|
||||
|
||||
export type AudioOrVideoPlayerProps = {
|
||||
url: string;
|
||||
type: "audio" | "video";
|
||||
captionTrack?: MediaCaptionTrack;
|
||||
};
|
||||
|
||||
const EMPTY_CAPTIONS_VTT = "data:text/vtt;charset=utf-8,WEBVTT%0A%0A";
|
||||
|
||||
function getCaptionTrackProps(track?: MediaCaptionTrack) {
|
||||
return {
|
||||
src: track?.src ?? EMPTY_CAPTIONS_VTT,
|
||||
srcLang: track?.srcLang ?? "en",
|
||||
label: track?.label ?? i18nT("components.media.captions"),
|
||||
default: track?.default,
|
||||
};
|
||||
}
|
||||
|
||||
const AudioOrVideoPlayer = ({ url, type, captionTrack }: AudioOrVideoPlayerProps, ref: Ref<RefAudioOrVideo>) => {
|
||||
const audioRef = useRef<HTMLAudioElement | null>(null);
|
||||
const videoRef = useRef<HTMLVideoElement | null>(null);
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
get media() {
|
||||
return type === "video" ? videoRef.current : audioRef.current;
|
||||
},
|
||||
}));
|
||||
|
||||
const trackProps = getCaptionTrackProps(captionTrack);
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
{type === "video" ? (
|
||||
<video ref={videoRef} src={url} controls className="border-border-default bg-surface-neutral-secondary/90 w-full rounded-md border shadow-2xs">
|
||||
<track kind="captions" {...trackProps} />
|
||||
</video>
|
||||
) : type === "audio" ? (
|
||||
<audio ref={audioRef} src={url} controls className="border-border-default bg-surface-neutral-secondary/90 w-full rounded-md border shadow-2xs">
|
||||
<track kind="captions" {...trackProps} />
|
||||
</audio>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default forwardRef(AudioOrVideoPlayer);
|
||||
Reference in new issue
Block a user