feat: enhance stream URL handling and add initial offset support in VideoPlayer
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
export { VideoPlayer } from "./video-player";
|
||||
export type { VideoPlayerProps } from "./video-player";
|
||||
|
||||
|
||||
export { ChannelInfo } from "./channel-info";
|
||||
export type { ChannelInfoProps } from "./channel-info";
|
||||
|
||||
|
||||
@@ -4,10 +4,12 @@ interface VideoPlayerProps {
|
||||
src?: string;
|
||||
poster?: string;
|
||||
className?: string;
|
||||
/** Seek to this many seconds after metadata loads (broadcast sync on refresh). */
|
||||
initialOffset?: number;
|
||||
}
|
||||
|
||||
const VideoPlayer = forwardRef<HTMLVideoElement, VideoPlayerProps>(
|
||||
({ src, poster, className }, ref) => {
|
||||
({ src, poster, className, initialOffset }, ref) => {
|
||||
return (
|
||||
<div className={`relative h-full w-full bg-black ${className ?? ""}`}>
|
||||
<video
|
||||
@@ -16,6 +18,11 @@ const VideoPlayer = forwardRef<HTMLVideoElement, VideoPlayerProps>(
|
||||
poster={poster}
|
||||
autoPlay
|
||||
playsInline
|
||||
onLoadedMetadata={(e) => {
|
||||
if (initialOffset && initialOffset > 0) {
|
||||
e.currentTarget.currentTime = initialOffset;
|
||||
}
|
||||
}}
|
||||
className="h-full w-full object-contain"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -57,7 +57,11 @@ export default function TvPage() {
|
||||
const { data: broadcast, isLoading: isLoadingBroadcast } =
|
||||
useCurrentBroadcast(channel?.id ?? "");
|
||||
const { data: epgSlots } = useEpg(channel?.id ?? "");
|
||||
const { data: streamUrl } = useStreamUrl(channel?.id, token);
|
||||
const { data: streamUrl } = useStreamUrl(
|
||||
channel?.id,
|
||||
token,
|
||||
broadcast?.slot.id,
|
||||
);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Derived display values
|
||||
@@ -176,7 +180,11 @@ export default function TvPage() {
|
||||
}
|
||||
if (streamUrl) {
|
||||
return (
|
||||
<VideoPlayer src={streamUrl} className="absolute inset-0 h-full w-full" />
|
||||
<VideoPlayer
|
||||
src={streamUrl}
|
||||
className="absolute inset-0 h-full w-full"
|
||||
initialOffset={broadcast?.offset_secs}
|
||||
/>
|
||||
);
|
||||
}
|
||||
// Broadcast exists but stream URL resolving — show no-signal until ready
|
||||
|
||||
Reference in New Issue
Block a user