Why is this code not working? Adding video in kirby cms

What am I doing wrong?

<?php if ( $video = $page->video() ): ?>
<video width="480" height="270" autoplay loop muted>
    <source src="<?= $video->url() ?>" type="<?= $video->type() ?>" />
<?php endif ?>

This returns a field object, you have to convert it to a file object, see how to use a files field in your templates: Files | Kirby CMS

Hm it doesn’t help, or maybe I should use something else instead of video()?

What is video in your example? A files field?

How to set “file” instead of “video” it works. For photos I use ‘image’, and for video you have to use ‘file’?

<video width="480" height="270" autoplay loop muted>
    <source src="<?= $page->file('video.mp4')->url() ?>" type="video/mp4" />

The code above works, but if you tell me how to add a single video to a page and several videos from a folder, I’d be grateful, because I don’t know if it’s good what I’m doing?

As far as I can tell, there’s no ->video() method available in Kirby. ->image(), when used with no arguments returns the first image but you can’t do the same with videos.

If you want to fetch videos you can use the ->videos() method: $page->videos() | Kirby CMS

It’s never a good idea to call a method (url in this case) without checking if you have an object first. You need an if statement here.