Draft: Initial Attempt at at integrating the photoswipe-video-plugin to allow mp4 Media to be dispalyed in the photoswipe gallery
This module allows Photoswipe to also display mp4 videos in galleries via the photoswipe-video-plugin.
This is still work in progress and while it can be used, there are still things to be added (Tests, Support for Responsive Images) and Issues to resolve. I pushed this initial version to verify that the approach is correct and to get some help/opinions with the issues mentioned at the end of the comment.
The module was designed to work without any changes to the Photoswipe module code*. As such there is some duplication of code between this and the the Photoswipe module, mostly in the template preprocess function.
The module provides a field formatter that extends the PhotoswipeFieldFormatter and can display Images and videos.
Due to the fact that Photoswipe's template preprocess function assumes that the media entity will be an image, I had to implement a new template preprocessor and provide a new template for the field.
The module also provides a VideoDTO class which extends the ImageDTO class provided by Photoswipe.
Video Thumbnails:
If the Media Thumbnails VIdeo module is installed, the thumbnails generated by it are used as the gallery thumbnails for the videos. If the module is not installed we use a default image that can be set in the Photoswipe Video Settings.
Issues that need to be resolved
Library not available in UDM format:
Currently the photoswipe-video-plugin does not include a UDM build in it's distributed form. I did try to use the ESM plugin but couldn't manage to get it working. I have created an issue on the project's Github page and submitted a pull request with the required updates to the projects rollup configuration so that a UDM version is also generated.
Instructions on how to generate the UDM version are included in the README.
Default Thumbnail Issue:
It's important that Videos have a thumbnail set otherwise we don't have anything to show in the gallery view for a video.
I am not sure what the best way to provide a default option for this. I tried the following Approaches:
- Make the Default Thumbnail setting required in the Photoswipe Video settings. While this in theory should work, you can still use the Fieldformatter without providing the required field in the settings.
- Add the Default Thumbnail as a required option in the Field Formatter settings. Again you can change the Field Formatter in the field's Display settings and save without providing a value as long as you don't open the field formatter's settings form.
- Provide a Default Thumbnail as a file included in the module. This is the current implementation. The idea is if no default thumbnail is provided in the Photoswipe Video settings, there is an image we fall back to and use as a thumbnail. The problem I face here, is I can't apply image styles to it as it's not in the public:// filesystem. This could be overcome by using the System stream wrapper module, but it seems like overkill to require a whole new module just to generate a default thumbnail.
Other Issues/Questions
Should we automatically overlay a play button over video thumbnails when viewed in the gallery? By default the plugin does not do this and video thumbnails look exactly like image thumbnails.
- The Photoswipe Dynamic Caption uses a hardcoded list of plugin id's it attaches to. We will eventually need to add the new one to that list if it's going to work with the new FieldFormatter