-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(ui): display video thumbnail #7374
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?
feat(ui): display video thumbnail #7374
Conversation
Are there any clarifications I can provide or changes that should be made to this? |
Revisiting this one. Are you able to resolve merge conflicts @willybrauner ? |
0bc092b
to
41e3396
Compare
@denolfe it's rebased on beta. |
9c6e646
to
0dbd0fc
Compare
@denolfe I updated this PR with the last beta. One unit test failed, but I'm not sure to know how to fix it. |
Since the failing e2e test is uploads, it's likely either a legitimate failure or the test needs to be updated (could just be a small selector tweak). To troubleshoot:
![]()
![]()
If I had to guess, it's likely looking for a selector that was changed/removed. |
0dbd0fc
to
c731940
Compare
@denolfe I have improved the Thumbnail component by mixing |
10635e3
to
cc4220d
Compare
For some reason I can't checkout to this PR locally whatsoever... However, you should comment that test back in because it checks for the existence of the thumbnail. Your code specifically shows nothing if the filetype is neither an image or a video, instead to keep our backwards compatibility, you should turn this into a {fileExists && fileType === 'image' && <img alt={alt} src={src} />} I'm not sure why the test would fail in this case anyhow |
cc4220d
to
191a8ad
Compare
@paulpopus nice catch, you're right about the image fallback, I have fixed it in this way. @denolfe. Thanks for the test usage explanation; I was able to run and trace it locally. The initial error was due to the preload "if else" statement, depending to the mimeType, on the same way than the render function. I have finally implemented an alternative than the ![]() |
Seems to be pretty quick with this method :) screen.mov |
@paulpopus @denolfe is this approach could be a right one for you? |
@willybrauner interesting pattern, I don't think we're opposed to it here, though this logic would need to be moved behind an observer since it would likely harm performance when viewing 50-100 thumbnails at once, which some projects using payload do. We have this intersect hook if you manage to use it https://github.com/payloadcms/payload/blob/beta/packages/ui/src/hooks/useIntersect.ts#L13 |
38474aa
to
9dc8a5f
Compare
@paulpopus I have rebase this branch on the last beta and implemented the observer. One new test failed but strangely, it continue to failed locally when I checkout on the previous commit. |
I think that's a flaky test so you can ignore it, now sorry to yoyo you back in this PR but we've had some performance issues with thumbnails in the bulk editor (trying to upload 50+ items at once) and I wonder if we may see the same problem here. See this PR: #8944 So we're sticking to a similar pattern, rendering a thumbnail onto an offscreen canvas but it's done higher up so that it can be handled sequentially so it doesn't block the main UI thread. Anyway that's to say, we could probably move the thumbnail logic into that new createThumbnail utility and move it higher up in the form manager. Thoughts? |
@paulpopus yes sure. Now we have this ˋcreateThumnail` function, the video thumbnail should be generated into it as for images I guess. Let me try to re implement it in the next days. |
9dc8a5f
to
c9c3559
Compare
|
||
// Convert the OffscreenCanvas to a Blob and free up memory | ||
canvas | ||
.convertToBlob({ type: 'image/jpeg', quality: 0.25 }) |
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.
@paulpopus In last commit, my logic migration inside the createThumbnail function. I refactored the base 64 url generation so that it is common to all types of media. Some notes:
|
@willybrauner Thanks for the updates
I tested this PR as it is so I think we're nearly ready to go, if you make the above changes and fix tests we can merge it! Edit: To add 4. when initially uploading a video, it's not showing the preview and just shows the document icon, there we might be able to pass File as well to create a thumbnail immediately for the user |
2b5cd55
to
ff3f6a9
Compare
fileSrc={src} | ||
key={src} |
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.
Due to a side effect of the new hasPreloaded
state in Thumbnail
before:
Screen.Recording.2024-11-07.at.18.41.47.mov
after add src
as key to force rerender:
Screen.Recording.2024-11-07.at.18.42.34.mov
@@ -157,7 +156,8 @@ export function FileSidebar() { | |||
> | |||
<Thumbnail | |||
className={`${baseClass}__thumbnail`} | |||
fileSrc={isImage(currentFile.type) ? thumbnailUrls[index] : undefined} |
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.
@paulpopus That was the reason why video thumbnail wasn't display before we saved the media.
Hi @paulpopus,
|
07355d6
to
d2ce3fb
Compare
769c397
to
d2e4ebd
Compare
…image and video media type.
d2e4ebd
to
c3703b9
Compare
This PR is stale due to lack of activity. To keep the PR open, please indicate that it is still relevant in a comment below. |
Sorry, I couldn't adapt the e2e tests properly. But the feature has been developed and is working. |
Thank you for your patience on this one @willybrauner . I still think this would be a good one to get in. We'll come up with a way forward. |
Description
This PR is about displaying a video thumbnail in
Thumbnail
component if the uploaded file has mimeTypevideo/*
. To avoid performance issue, the video is not played, only the first frame is displayed from a<video>
tag, but it can be managed differently (with intersection observer, click handler etc.)When you manage a large collection of assets/files, it is very difficult to quickly find a video by file name, video preview can help to identify the file by its first frame.
After change :
video-thumbnail.mov
Type of change
Checklist: