From 5dcb52015cb690be631a2e3121241d13a1c551ad Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 4 Sep 2024 19:57:16 +0100 Subject: add video to embed (#5145) --- bskyembed/src/components/embed.tsx | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'bskyembed/src') diff --git a/bskyembed/src/components/embed.tsx b/bskyembed/src/components/embed.tsx index 600c7c2c3..3b4f5e77d 100644 --- a/bskyembed/src/components/embed.tsx +++ b/bskyembed/src/components/embed.tsx @@ -3,6 +3,7 @@ import { AppBskyEmbedImages, AppBskyEmbedRecord, AppBskyEmbedRecordWithMedia, + AppBskyEmbedVideo, AppBskyFeedDefs, AppBskyFeedPost, AppBskyGraphDefs, @@ -14,6 +15,7 @@ import {ComponentChildren, h} from 'preact' import {useMemo} from 'preact/hooks' import infoIcon from '../../assets/circleInfo_stroke2_corner0_rounded.svg' +import playIcon from '../../assets/play_filled_corner2_rounded.svg' import starterPackIcon from '../../assets/starterPack.svg' import {CONTENT_LABELS, labelsToInfo} from '../labels' import {getRkey} from '../utils' @@ -160,7 +162,12 @@ export function Embed({ return null } - // Case 4: Record with media + // Case 4: Video + if (AppBskyEmbedVideo.isView(content)) { + return + } + + // Case 5: Record with media if ( AppBskyEmbedRecordWithMedia.isView(content) && AppBskyEmbedRecord.isViewRecord(content.record.record) @@ -354,6 +361,31 @@ function GenericWithImageEmbed({ ) } +// just the thumbnail and a play button +function VideoEmbed({content}: {content: AppBskyEmbedVideo.View}) { + let aspectRatio = 1 + + if (content.aspectRatio) { + const {width, height} = content.aspectRatio + aspectRatio = clamp(width / height, 1 / 1, 3 / 1) + } + + return ( +
+ {content.alt} +
+ +
+
+ ) +} + function StarterPackEmbed({ content, }: { @@ -410,3 +442,7 @@ function getStarterPackHref( const handleOrDid = starterPack.creator.handle || starterPack.creator.did return `/starter-pack/${handleOrDid}/${rkey}` } + +function clamp(num: number, min: number, max: number) { + return Math.max(min, Math.min(num, max)) +} -- cgit 1.4.1