-
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
5b3c6f0
08835be
3463988
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,62 @@ | ||
| import type { FEAspectRatio } from '../frontend/feFront'; | ||
| import type { ArticleFormat } from '../lib/articleFormat'; | ||
| import { | ||
| convertAssetsToVideoSources, | ||
| getFirstVideoAsset, | ||
| 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; | ||
| const firstVideoAsset = getFirstVideoAsset(element.assets); | ||
|
|
||
| if (!posterImageUrl) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <SelfHostedVideo | ||
| atomId={element.id} | ||
| fallbackImage={posterImageUrl} | ||
| fallbackImageAlt={caption} | ||
| fallbackImageAspectRatio={ | ||
| (firstVideoAsset?.aspectRatio ?? '5:4') as FEAspectRatio | ||
| } | ||
| fallbackImageLoading="lazy" | ||
| fallbackImageSize="small" | ||
| height={firstVideoAsset?.dimensions?.height ?? 400} | ||
| linkTo="Article-embed-MediaAtomBlockElement" | ||
|
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. What is this magic string @RikRootsGuardian ?
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 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? |
||
| posterImage={posterImageUrl} | ||
| sources={convertAssetsToVideoSources(element.assets)} | ||
| subtitleSize="medium" | ||
| subtitleSource={getSubtitleAsset(element.assets)} | ||
| videoStyle="Loop" | ||
| uniqueId={element.id} | ||
| width={firstVideoAsset?.dimensions?.width ?? 500} | ||
| /> | ||
| {!!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
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. I don't think that the However I can see why it looks that way as the code is confusing as it is and could be tidied up. Maybe This would have the benefit of all the logic around the poster image living in one place, the accessing of the Happy to chat through this further.
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. Thanks for this, I'll let @RikRootsGuardian respond when he's back |
||
|
|
||
| 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.
Does this need to be an island? Since
SelfHostedVideois an island, I don't think this needs to be. I don't believe there's any harm to it, since this PR, but it might be unnecessary.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.
Good catch, I've removed it: 5b3c6f0