diff --git a/src/TwigExtension.php b/src/TwigExtension.php
index a54ee10..bc97ace 100644
--- a/src/TwigExtension.php
+++ b/src/TwigExtension.php
@@ -7,6 +7,7 @@ use Drupal\Core\Site\Settings;
 use Drupal\Core\Url;
 use Drupal\image\Entity\ImageStyle;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
+use Drupal\media_entity\MediaInterface;
 
 /**
  * Twig extension with some useful functions and filters.
@@ -19,7 +20,7 @@ class TwigExtension extends \Twig_Extension {
    * {@inheritdoc}
    */
   public function getFunctions() {
-    return [
+    $functions = [
       new \Twig_SimpleFunction('drupal_view', 'views_embed_view'),
       new \Twig_SimpleFunction('drupal_block', [$this, 'drupalBlock']),
       new \Twig_SimpleFunction('drupal_region', [$this, 'drupalRegion']),
@@ -37,6 +38,12 @@ class TwigExtension extends \Twig_Extension {
       new \Twig_SimpleFunction('drupal_title', [$this, 'drupalTitle']),
       new \Twig_SimpleFunction('drupal_url', [$this, 'drupalUrl']),
     ];
+
+    if (\Drupal::moduleHandler()->moduleExists('media_entity')) {
+      $functions[] = new \Twig_SimpleFunction('media_file_url', [$this, 'mediaFileUrl']);
+    }
+
+    return $functions;
   }
 
   /**
@@ -366,6 +373,25 @@ class TwigExtension extends \Twig_Extension {
   }
 
   /**
+   * Returns the file URL from a media entity.
+   *
+   * @param \Drupal\media_entity\MediaInterface $media_entity
+   *   The media entity object.
+   *
+   * @return string
+   *   The file url.
+   */
+  public function mediaFileUrl(MediaInterface $media_entity) {
+    $source_field = $media_entity->getType()->getConfiguration()['source_field'];
+    if ($media_entity->hasField($source_field)) {
+      $file_entities = $media_entity->get($source_field)->referencedEntities();
+      if (!empty($file_entities)) {
+        return $file_entities[0]->getFileUri();
+      }
+    }
+  }
+
+  /**
    * Replaces all tokens in a given string with appropriate values.
    *
    * @param string $text
