How to add autoplay, loop, mute and other attributes to Videos

Hey folks,

iam trying to figure out how to add attributes like “autoplay”, “muted” and “loop” to a video.
The framework is a customized Kirby 3.9 Starter Kit.

The video was uploaded in panel. blueprints/pages/project.yml here:

…
images:
  label: Medien
  type: files
  template: image
  info: "{{ file.dimensions }}"
  image:
    cover: true
…

blueprints/files/image.hml here:

…
accept: 
  type:
    - image
    - video
…

Building it via Layout/Blocks. blueprints/pages/project.yml here:

  content_media:
    label: Layout
    fields:
      layout:
        label: Layout
        type: layout
        fieldsets:
          - image
          - heading
          - text
          - video
          - code
…

snippet/blocks/video here:

<?php if ($block->url()->isNotEmpty()): ?>
<figure>
  <span class="video">
    <?= video($block->url()) ?>
  </span>
  <?php if ($block->caption()->isNotEmpty()): ?>
  <figcaption class="video-caption"><?= $block->caption() ?></figcaption>
  <?php endif ?>
</figure>
<?php endif ?>

I think this is the place where the magic should happens :wink:

<?= video($block->url()) ?>

Goal…

<video autoplay muted loop>
…
</video>

Hope there is anybody who can give help or a little hint.

Thank you in advance!
Regards

Check out the docs for the video helper: video() | Kirby CMS

It has some examples

Hey,

tank you for your answer. Ive already checked this. But this only works with YouTube/Vimeo linked videos. The video-files I use are local.

Iam not a crack on php… so please be lenient^^

regards

The video() helper is intended for YouTube or Vimeo videos, you cannot use it for local videos. For local videos, you have to use the HTML video element:

snippets/blocks/video.php

<?php if ($block->url()->isNotEmpty()): ?>
<figure>
  <span class="video">
    
    <video autoplay loop muted>
      <source src="<?= $block->url() ?>">
    </video>

  </span>
  <?php if ($block->caption()->isNotEmpty()): ?>
  <figcaption class="video-caption"><?= $block->caption() ?></figcaption>
  <?php endif ?>
</figure>
<?php endif ?>

THX texnixe

Hey @N3riu2 Can you please send all the code of your snippets/blocks/video.php ?
I don’t understand what is

Thank you a lot