Skip to content

Commit

Permalink
Add startTime prop
Browse files Browse the repository at this point in the history
  • Loading branch information
third774 committed Dec 17, 2021
1 parent 21ffff3 commit d15d44d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ export type StreamProps = {
* The <video> element does not force the browser to follow the value of this attribute; it is a mere hint. Even though the preload="none" option is a valid HTML5 attribute, Stream player will always load some metadata to initialize the player. The amount of data loaded in this case is negligable.
*/
preload?: "auto" | "metadata" | "none" | boolean;
/**
* A timestamp that specifies the time when playback begins.
* If a plain number is used such as ?startTime=123, it will
* be interpreted as 123 seconds. More human readable timestamps
* can also be used, such as ?startTime=1h12m27s for 1 hour,
* 12 minutes, and 27 seconds.
*/
startTime?: string | number;
/**
* Automatically manages the aspect ratio of the iframe for you. Defaults to true. If you want to manually handle the styles yourself, set this to false.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Stream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const StreamEmbed: FC<StreamProps> = ({
poster,
currentTime = 0,
volume = 1,
startTime,
streamRef,
responsive = true,
className,
Expand Down Expand Up @@ -154,6 +155,7 @@ export const StreamEmbed: FC<StreamProps> = ({
primaryColor,
adUrl,
defaultTextTrack,
startTime,
});

// While it's easier for most consumers to simply provide the video id
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ export interface StreamProps {
* Either the video id or the signed url for the video you’ve uploaded to Cloudflare Stream should be included here.
*/
src: string;
/**
* A timestamp that specifies the time when playback begins.
* If a plain number is used such as ?startTime=123, it will
* be interpreted as 123 seconds. More human readable timestamps
* can also be used, such as ?startTime=1h12m27s for 1 hour,
* 12 minutes, and 27 seconds.
*/
startTime?: string | number;
/**
* Ref for accessing the underlying stream element. Useful for providing imperative access to the player API:
* https://developers.cloudflare.com/stream/viewing-videos/using-the-player-api
Expand Down
4 changes: 4 additions & 0 deletions src/useIframeSrc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface IframeSrcOptions {
controls?: boolean;
poster?: string;
primaryColor?: string;
startTime?: string | number;
adUrl?: string;
defaultTextTrack?: string;
preload?: Preload;
Expand All @@ -24,6 +25,7 @@ export function useIframeSrc(
poster,
primaryColor,
adUrl,
startTime,
defaultTextTrack,
}: IframeSrcOptions
) {
Expand All @@ -33,11 +35,13 @@ export function useIframeSrc(
defaultTextTrack &&
`defaultTextTrack=${encodeURIComponent(defaultTextTrack)}`,
primaryColor && `primaryColor=${encodeURIComponent(primaryColor)}`,
startTime && `startTime=${startTime}`,
muted && "muted=true",
preload && `preload=${preload}`,
loop && "loop=true",
autoplay && "autoplay=true",
!controls && "controls=false",
"version=build.1638815245",
]
.filter(Boolean)
.join("&");
Expand Down

0 comments on commit d15d44d

Please sign in to comment.