The FileVideoFormatter in core does not provide any thumbnail by default with local video uploads.
Luckily (?), most browsers like Chrome are smart enough to supply the first frame of the video as the thumbnail, but this is not something iOS Safari does.
The generated HTML for the current fieldformatter looks something like this:
<div class="field field--name-field-media-video-file field--type-file field--label-hidden field__item">
<video controls="controls" width="1024" height="576">
<source src="/sites/default/files/2019-05/somevideo.mp4" type="video/mp4">
</video>
</div>
I found out that by adding preload="metadata" to the video tag and suffixing "#t=1" to the source files "src" attribute, it adds the wanted behavior to Safari iOS.
I've created a patch for adding this functionality. After adding the patch, video fields will look something like this:
<div class="field field--name-field-media-video-file field--type-file field--label-hidden field__item">
<video controls="controls" width="1024" height="576" preload="metadata">
<source src="/sites/default/files/2019-05/somevideo.mp4#t=1" type="video/mp4">
</video>
</div>
Issue fork drupal-3079425
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ras-ben commentedComment #3
ras-ben commentedComment #4
ras-ben commentedComment #7
ras-ben commentedRe-rolled against 8.7.7
Comment #8
arnested commentedComment #9
ras-ben commentedSigh - i forgot a "use", so it would fail in certain cases..
Comment #10
samberry commentedI tried out the patch in #9 but found that the 1 second set for the 'thumbnail_second' variable was too late, as videos were starting from 1 second in. I have therefore modified the patch to remove the min of 1 to the thumbnail_second and set this by default to 0.01.
I feel like this may be a bit of a workaround though, and I'm not sure that this should be the final version.
Comment #12
samberry commentedRealised decimals won't work if its a number field - updated to textfield!
Comment #13
ras-ben commented@samberry - why not just use decimal fieldtype?
I think using textfield would be wrong - and would probably open up to a security issue as we dont escape it or anything before adding it to the src :)
Comment #14
platinum1 commented@ras-ben I am dealing with this problem right now. Is development of your solution continuing?
Comment #15
ras-ben commented@platinum1 Well, it's quite a while ago now since i looked at this
My own patch #7 solved my issue, but @samberry does have a valid point in his patches #10 and #12
Seeing as this is an issue against core, and it's a relative edgecase, I've never had the highest hopes that this would be merged any time soon.
But you are very welcome to build onto samberry's solution and deal with my latest comment.
I'll be happy to review it if you do - i dont expect it's a big fix :)
Comment #17
ras-ben commentedRe-rolled against 9.2.
Comment #19
samberry commentedSo I've managed to include the step attribute which provides the ability to add a decimal value, I've also added thumbnail_second to the schema.
Comment #20
avpadernoDrupal 8.9.x is now open only to security issues.
Comment #21
inaw commentedI tested the patch #19 and had to change the field type in schema.yml to float, to be able to successfully save decimal numbers in the thumbnail_second.
Otherwise, the patch seems to work fine with Drupal 9.2.x.
Comment #23
rollins commentedI can confirm that #21 resolved bug
Thanks InaW!
Comment #28
_shyRerolled patch. Also added test fixes.
Comment #29
_shyComment #30
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #32
_shyUpdated patch to be able to apply it for the Drupal 10.3.1