The solution is probably very simple, but still, I am struggling to understand how to make it work.
We are preparing for the new school year, and of course, we’re required to make things work remotely. We will have a bunch of educational videos posted on Youtube, and an external Windows app will make sure everything is well organized and that teachers can easily upload new videos (via Youtube API), and that teachers can quickly share material to students.
And, when a teacher wants to send a video to students, he will obviously give them a link. They decided that they want videos to be played outside Youtube (for a number of reasons).
We have a WordPress website that is already functional, and which we can use to display Youtube videos that we can embed.
A WordPress page would have embed code for Youtube player, which is provided by Youtube.
But, the issue is that I don’t understand how to make video ID changeable (b_DcQHbJIfE) so that one page can play any video which the Windows app sends.
Example:
External Windows app sends: https://www.externalvideoplayer.com/player/b_DcQHbJIfE
A website gets “b_DcQHbJIfE” and actually plays it on the embedded player
App then sends another video, like this: https://www.externalvideoplayer.com/player/c_gcOWSJISe
A website gets and plays “c_gcOWSJISe”
I know a little bit of PHP, and stumbled upon this code:
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; echo $actual_link;
But I am not sure if that would work when the page is loading, since the Windows app probably opens a URL that does not exist.
Any help would be greatly appreciated! Thanks!
Advertisement
Answer
I figured this out, here’s the code:
<!DOCTYPE HTML> <HTML> <?php $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $url_ID = array_pop(explode('/', $actual_link)); ?> <iframe width="800" height="800" src="https://www.youtube.com/embed/<?php echo $url_ID?>" frameborder="0" gesture="media" allow="autoplay; encrypted-media" allowfullscreen></iframe> </html>
So now, when you load this PHP file, and if you add “/VIDEO ID” (https://www.example.com/test.php/c_gcOWSJISe)
The page will load any video that you enter into the URL. Note that this probably does not work on the localhost server, so you need actual server and domain to make this work.
Thanks!