-
Notifications
You must be signed in to change notification settings - Fork 30
Add looping videos to articles #14843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
628437b
db38c0d
452600e
679f799
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import type { ArticleFormat } from '../lib/articleFormat'; | ||
| import { convertAssetsToVideoSources, getSubtitleAsset } from '../lib/video'; | ||
| import type { MediaAtomBlockElement } from '../types/content'; | ||
| import { Caption } from './Caption'; | ||
| import { SelfHostedVideo } from './SelfHostedVideo.importable'; | ||
|
|
||
| type LoopVideoInArticleProps = { | ||
| element: MediaAtomBlockElement; | ||
| format: ArticleFormat; | ||
| isMainMedia: boolean; | ||
| }; | ||
|
|
||
| export const LoopVideoInArticle = ({ | ||
| element, | ||
| format, | ||
| isMainMedia, | ||
| }: LoopVideoInArticleProps) => { | ||
| const posterImageUrl = element.posterImage?.[0]?.url; | ||
| const caption = element.title; | ||
|
|
||
| if (!posterImageUrl) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <SelfHostedVideo | ||
| atomId={element.id} | ||
| fallbackImage={posterImageUrl} | ||
| fallbackImageAlt={caption} | ||
| fallbackImageAspectRatio="5:4" | ||
| fallbackImageLoading="lazy" | ||
| fallbackImageSize="small" | ||
| height={400} | ||
| linkTo="Article-embed-MediaAtomBlockElement" | ||
| posterImage={posterImageUrl} | ||
| sources={convertAssetsToVideoSources(element.assets)} | ||
| subtitleSize="medium" | ||
| subtitleSource={getSubtitleAsset(element.assets)} | ||
| videoStyle="Loop" | ||
| uniqueId={element.id} | ||
| width={500} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looping videos are 5:4, as mandated by Editorial and Design. All other videos currently displaying in articles (youtube + legacy self-hosted) play in 16:9. There's been no consideration of how to display 4:5 or 9:16 videos in Articles (at least we've not been told of these plans). Similarly no news on the aspect ratios of the new "Cinemascope" videos. There's also a wider issue around moving normal images to 5:4 AR in articles. This is where we stare at Calvin and ask for guidance.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Cool, this gives me confidence 👍 thanks! |
||
| /> | ||
| {!!caption && ( | ||
| <Caption | ||
| captionText={caption} | ||
| format={format} | ||
| isMainMedia={isMainMedia} | ||
| mediaType="SelfHostedVideo" | ||
| /> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,8 +87,8 @@ const dispatchOphanAttentionEvent = ( | |
| document.dispatchEvent(event); | ||
| }; | ||
|
|
||
| const getOptimisedPosterImage = (mainImage: string): string => { | ||
| const resolution = window.devicePixelRatio >= 2 ? 'high' : 'low'; | ||
| const getOptimisedPosterImage = (mainImage: string, dpr: number): string => { | ||
| const resolution = dpr >= 2 ? 'high' : 'low'; | ||
|
|
||
| return generateImageURL({ | ||
| mainImage, | ||
|
|
@@ -190,6 +190,8 @@ export const SelfHostedVideo = ({ | |
| const [hasBeenPlayed, setHasBeenPlayed] = useState(false); | ||
| const [hasTrackedPlay, setHasTrackedPlay] = useState(false); | ||
|
|
||
| const [devicePixelRatio, setDevicePixelRatio] = useState(1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Introducing state feels a bit unnecessary here, what was your thinking?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bug in the new LoopVideo player. The bug tries to access the browser |
||
|
|
||
| const VISIBILITY_THRESHOLD = 0.5; | ||
|
|
||
| /** | ||
|
|
@@ -365,6 +367,8 @@ export const SelfHostedVideo = ({ | |
| } | ||
| }); | ||
|
|
||
| setDevicePixelRatio(window.devicePixelRatio); | ||
|
|
||
| return () => { | ||
| document.removeEventListener( | ||
| customSelfHostedVideoPlayAudioEventName, | ||
|
|
@@ -673,7 +677,7 @@ export const SelfHostedVideo = ({ | |
| const AudioIcon = isMuted ? SvgAudioMute : SvgAudio; | ||
|
|
||
| const optimisedPosterImage = showPosterImage | ||
| ? getOptimisedPosterImage(posterImage) | ||
| ? getOptimisedPosterImage(posterImage, devicePixelRatio) | ||
| : undefined; | ||
|
|
||
| return ( | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this magic string @RikRootsGuardian ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be considered. It's used for tracking events eg when video first comes into view. This was developed with Fronts in mind, so I don't know if that tracking is useful for progression through the article? I put it in as a hardcoded text, but maybe a better approach would be to use the article URL here?