Videop.php <b>Fatal error</b>: Call to a member function url()

Hi. It’s been a while since I tried to edit my kirby installation but wanted to add some videos. Using the preinstalled video.php snippet, I copied this code from github

<?php
	$videos = array(
  $page->videos()->find('htmlvideo.mp4'),
  $page->videos()->find('htmlvideo.mobile.mp4'),
  $page->videos()->find('htmlvideo.webm'),
  $page->videos()->find('htmlvideo.ogv'),
);

snippet('video', array(
  'videos' => $videos,
  'thumb'  => $page->images()->find('htmlvideo.jpg'),
  'width'  => 400,
  'height' => 300
));
?>

and placed it at the end of my default.php template

I get:
Fatal error: Call to a member function url() on a non-object in /home/shitless/public_html/kirby/site/snippets/video.php on line 19

Example:
http://studioshitless.com/kirby/vidTest

To the best of my knowledge, I’m using version 1 of Kirby.

My first advise would be to upgrade it to Kirby 2 – as blunt as this might sound.

And, to be 100% clear, you definitely have all of those videos saved in your page directory?

The reason I ask is that if a video doesn’t exist, as far as I can tell from the source code, $page->videos()->find($key) ultimately falls back on a::get($fileArray, $key), where the default would return null, which is not a file object and would produce that error message.

My first advise would be to upgrade it to Kirby 2v

Hi. I’ll consider it. At first glance, I thought Kirby 2 looked a bit more complex than Kirby 1.

And, to be 100% clear, you definitely have all of those videos saved in your page directory?

I feel a bit stupid. I assumed that it finds all the mp4s in the folder in the same way as it does jpgs. But when I looked at that code I couldn’t really see how it worked but hoped for the best. I guessed that ‘htmlvideo’ was some kind of wild-card.

Is there a full code example that finds all mp4s? Irrespective of their names?

maybe this could work:

$videos = $page->files()->filterBy('extension', 'mp4');