Lmxc
Lmxc

Reputation: 283

playing videos on second page php

This is kind of stupid question but is there any way to play videos just by using two pages, I mean like instead of creating an html page for every video I upload to my website, can I have only two php pages and then pass the video from the first page and play on the second one?

I know about passing variables in url but I am kinda confused on how to do this.

I actually embedded my videos from google drive and have a format like

<iframe src="https://docs.google.com/file/d/0B5ZMsnZoUVNSWHhxeGc/preview" width="640" height="385"></iframe>

would it be possible to do like

<a href="play.php?video='test.mp4'>Click to play</a>

or like

$video= 'test.mp4';
<a href="play.php?vid='$video'>Click to play</a>

play.php

  $video = $_GET['vid']
 if(!empty(($video)){

//then play the video here.   
 }

Upvotes: 0

Views: 1103

Answers (3)

user2801966
user2801966

Reputation: 468

<a href="play.php?video=test.mp4"> Play This Video</a>

And On Play.php page add this code

if(isset($_GET['video'])&&!empty($_GET['video']))
{
    $Video = $_GET['video'];
    // Use the Source of your video anyway you like to play the video
}else
{
    echo 'No video selected to play';
}

Upvotes: 0

darshandzend
darshandzend

Reputation: 394

I'm expecting you're usnig HTML5.

Let's say there's a list of videos on the first page, and you click on a name of video and it redirects you to second page. Pass the video url (or any identifier for server to know which video) in the link. You can do it like

<a href="page2.php?vid_url=/path/to/cats.mp4">Cats!!</a>

This will send vid_url as a GET variable on second page. page2.php is, as you can imagine, very simple

<?php

$vid = $_GET['vid'];

//echo $vid;

echo "<video width='320' height='240' controls>
         <source src=".$vid." type='video/mp4'>
         Your browser does not support the video tag.
     </video>"

?>

Of course, you'll do something more elaborate than simply using "echo" for formatted HTML output.

Upvotes: 1

sskoko
sskoko

Reputation: 839

Yes. Instead of empty use isset:

if (isset($_GET["vid"])){
   $video = $_GET['vid'];
   //play video
}

Upvotes: 0

Related Questions