- Issue created by @paulsheldrake
- π¨π¦Canada paulsheldrake
paulsheldrake β changed the visibility of the branch 3417063-add-support-remote-video to hidden.
- last update
about 1 year ago 6 pass - Status changed to Needs review
about 1 year ago 3:08pm 26 January 2024 - π©π°Denmark Steven Snedker
Thank you!
I can confirm it works with a short URL like https://vertikal.dk/sites/default/files/keys.mp4
On URLs longer than 245 chars it breaks. Because the name of the video is supposed to fit in 255 chars.
In the MediaRemoteVideoFormatter.php I changed
public static function deriveMediaDefaultNameFromUrl($url) { $pattern = static::getUrlRegexPattern(); if (preg_match($pattern, $url)) { return t('Video from @url', [ '@url' => $url, ]); } return parent::deriveMediaDefaultNameFromUrl($url); }
to
public static function deriveMediaDefaultNameFromUrl($url) { $pattern = static::getUrlRegexPattern(); if (preg_match($pattern, $url)) { return t('Video from @url', [ '@url' => substr($url, 0, 200), ]); } return parent::deriveMediaDefaultNameFromUrl($url); }
to make it work.
I also had to relax getUrlRegexPattern() in order to make videos like
http://mywonderfulNAS.myds.me:8764/share.cgi/Homevideo%20U-Matic/1061.mp...
almost work.In the MediaRemoteVideoFormatter.php I changed
public static function getUrlRegexPattern() { return '/^https?.*?\.mp4/'; }
to
public static function getUrlRegexPattern() { return '/^http?.*/'; }
The player is still adamant that "No video with supported format and MIME type found" - but this is probably not related to this module or this formatter.
At least the player will get the correct url this way.
- π©π°Denmark Steven Snedker
Having the video(url) show up in the media library added no benefits to my project, I found.
So I ended up with a simpler solution than installing, patching, tweaking and setting up the Media Remote module:
function mymodule_preprocess_node(&$variables) { if (!empty($variables['node']->get('field_video')->value)) { $video_link = $variables['node']->get('field_video')->value; $variables['content']['field_video'] = [ '#type' => 'inline_template', '#title' => 'Video', '#template' => '<video controls><source src="{{ url }}" type="video/mp4"></video>', '#context' => ['url' => $video_link], ]; }
If you have a text field called video in a node, and you type in a remote video url, when editing the node, a video player will appear when viewing the node, instead of the text.
Video urls should be https://. Otherwise your browser might not play the video and might give you a strange error message
I hope someone will save some hours.
- πΊπΈUnited States uri_frazier Portland, Oregon
Works well for me, thank you!