How to play random video from YouTube in Javascript?

Hi Everyone,
So, I wanted to play a completely random video from YouTube, does anyone know how to do this in JavaScript?

I have got a VideoJS player and will add YouTube video support myself.
I just need an idea of how to get a random video, I know I can make abcd1234… random strings and put it with Math.random() but there is one problem what if the video is private or it has been removed then this will not work.

Thanks in advance.
Regards,
Mayank

This is very inefficient because in most cases you will get a non-existent URL

it is best to use an API that would then know about all existing videos (in the database)
as opposed to a randomly generated URL that will fail in 99.9% of cases



search YT with some term
and then from the results it throws out to run some random video

4 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.