Random video from a YouTube playlist (as video background)

Hello! :slight_smile:

I created a website that have a video in autoplay and loop in the background of the main hero section. It was created in Bricks > Background video > YouTube URL.

Now, I have been asked to show a random video from the clients’ YouTube channel, and I am wondering how can I achieve that…

I was thinking if it would be possible to add a YouTube playlist URL to Bricks, but no luck with that.

Also thinking if I could create something with conditions… But I am not sure if that would please the client, as it will be limited to certain YouTube URLs that I would have configured beforehand.

So I have no clue if it is something achievable with Bricks. Or if it has to be more of a feature request :woman_shrugging: - to be able to pull videos from a given playlist on YouTube.

Anyone has faced something like this before?

I know there might exist some plugins, but I would love to stick with Bricks native section and blocks.

Any input would be appreciated!

Thanks!!

You could create a custom function that fetches the contents of a YouTube playlist (using the YouTube API) and returns a random item.

Quick demo using this playlist:

https://bricks.andreslotta.dev/random-video/

Hi @aslotta !

With this solution, would I be able to make it work inside the “Background video” field in the Section?

If you check the source code in my example you see that it is actually using the section background video setting. :slight_smile:

Superb! :slight_smile: I’ll talk to my client and I may contact you to implement this on the site. Is it ok? :blush:

Sure. Just drop me a message…