0

I can't manage to get the video link of a media, I can achieve this with a picture but with videos it doesn't work.

This is the code I am using.

function slider_get_uri_by_media($media, $style = 'background'){
  // kint(isset($media->file_media_video_file));
  if (isset($media->field_media_image)){
    $file = $media->field_media_image->entity;
    if ($file && $fid = $file->id()) {
      $image = File::load($fid);
      if ($image_style = ImageStyle::load($style)) {
        return ['url' => file_url_transform_relative($image_style->buildUrl($image->getFileUri()))];
      }
    }
  }
  elseif (isset($media->file_media_video_file)) {
    $file = $media->file_media_video_file->entity;
    if ($file && $fid = $file->id()) {
      $video = File::load($fid);
    }
  }
}

Why cannot I get the path for the video stored in $media->field_media_video_file?

1

I think that you have a typo in the field name, you should replace $media->file_media_video_file with $media->field_media_video_file (2 times)