I currently provide all images in 4 resolutions (@1x
, @2x
, @3x
and @4x
) so that the images are sharply displayed on any display. But now I have the problem that I also have a video on the website and I want to provide the video and its preview image (the so-called poster) in the 4 resolutions as well. The question is how to do it as the video tag does not have its own srcset
, neither does the preview image.
I haven't found a built-in way to achieve this yet and I would like to avoid a JS-based solution if possible.
Maybe someone can help with a clever solution.
<video id="mockupVideo" width="100%" height="100%" playsinline preload="auto"
poster="images/test.jpg">
<source src="videos/test.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
I have the following image files:
images/test.jpg
images/test@2x.jpg
images/test@3x.jpg
images/test@4x.jpg
And these video files:
videos/test.mp4
videos/test@2x.mp4
videos/test@3x.mp4
videos/test@4x.mp4
With images I would use the following code:
<img srcset="images/test.jpg,
images/test@2x.jpg 2x,
images/test@3x.jpg 3x,
images/test@4x.jpg 4x"
src="images/test.jpg">
This is to be achieved in a similar way for the video.