Page 1 of 1

Play video links via php?

Posted: Thu Mar 14, 2019 7:27 am
by Dude
Hi, I want to put a bunch of video links on my website so that the user can click a link and then have that video open in a new tab and start playing. Currently I have to have 1 x HTM page for each video to make this work, but I'd rather have one target HTM page (called "player.htm") which knows the filename of the video link that was clicked, and then plays that video.

I can't work out how to do this, but apparently it can be done with PHP instead? Anyone know how? I'm looking for something like this:

Code: Select all

<a href="/video/player.php?file=video1.mp4">First video</a>
<a href="/video/player.php?file=video2.mp4">Second video</a>
...
Thanks.

Re: Play video links via php?

Posted: Thu Mar 14, 2019 9:31 am
by TI-994A
Dude wrote:...I'd rather have one target HTM page (called "player.htm") which knows the filename of the video link that was clicked, and then plays that video.

I can't work out how to do this, but apparently it can be done with PHP instead?
Even JavaScript is able to extract the URL query, but it's much easier with PHP.

player.php

Code: Select all

<?php 
  if (isset($_GET['file'])) {
    $file = $_GET['file'];
  }
?>

<!DOCTYPE html>
<html lang="en">  
  <body>
    <video id="player" width="640" height="480" controls>
    </video>
  </body>  
  <footer>
    <script> 
      var file = "<?= $file ?>";
      if (file.trim() != "") {
        var player = document.getElementById("player");
        var source = document.createElement("source");
        source.setAttribute("src", file);
        player.appendChild(source);
      } else {
        alert("Video source not found.");
      }
    </script>    
  </footer>  
</html>
Then, simply load the page as you would, with the video file name in the URL query:

Code: Select all

<a href="/video/player.php?file=video1.mp4">First video</a>
<a href="/video/player.php?file=video2.mp4">Second video</a>
...

Re: Play video links via php?

Posted: Thu Mar 14, 2019 12:40 pm
by Dude
Thanks a lot, TI-994A! :) Works nice as a start, so now I'll tweak the HTML to match my site. Appreciate it.

Re: Play video links via php?

Posted: Mon Mar 18, 2019 10:53 pm
by VB6_to_PBx
HTML Example : ( only checked out in FireFox Browser )

Code: Select all

<!DOCTYPE html> 
<html> 
<body> 
<button onclick="playPause()">Play/Pause</button>
<button onclick="enableLoop()" type="button">Enable loop</button>
<button onclick="disableLoop()" type="button">Disable loop</button><br>
<button onclick="setQuarterVolume()" type="button">Set volume to 25 %</button>
<button onclick="setHalfVolume()" type="button">Set volume to 50 %</button>
<button onclick="setFullVolume()" type="button">Set volume to 100 %</button>
<button onclick="VidSize640x480()" type="button">Video Size 640x480</button>
<button onclick="VidSize940x705()" type="button">Video Size 940x705</button>
<button onclick="VidSize1160x870()" type="button">Video Size 1160x870</button><br> 

<video id="myVideo" controls>
 /<source src="Black Night by Joe Bonamassa - Bonatube2013-1Qcexr6CZ5Y.mp4" type="video/mp4">
  Your browser does not support HTML5 video.
</video>

<script>
var vid = document.getElementById("myVideo");
vid.volume = 0.5;
vid.width = 940;
//vid.height = 705;

function playPause() { 
    if (myVideo.paused) 
        myVideo.play(); 
    else 
        myVideo.pause(); 
} 


function enableLoop() {
     if (myVideo.loop = true)
        disableLoop();
        //alert("Loop Disabled");
     else
        vid.loop = true;
        alert("Loop Enabled");
} 


function disableLoop() { 
  vid.loop = false;
  alert("Loop Disabled");
  //vid.load();
} 

function getVolume() { 
    alert(vid.volume);
} 

function setQuarterVolume() { 
    vid.volume = 0.25;
} 
  
function setHalfVolume() { 
    vid.volume = 0.5;
} 
  
function setFullVolume() { 
    vid.volume = 1.0;
} 

function VidSize640x480() { 
    vid.width = 640;
    //vid.height = 480;
} 

function VidSize940x705() { 
    vid.width = 940;
    //vid.height = 705;
} 

function VidSize1160x870() { 
    vid.width = 1160;
    //vid.height = 870;
} 

</script> 

</body> 
</html>



or real simple Example :

Code: Select all

<!DOCTYPE html> 
<html> 
<body> 
<iframe width="940" height="705" 
src="https://www.youtube.com/embed/MMB7Xf_7JDs?&vq=hd720&controls=1&autoplay=1&showinfo=1&rel=0"
frameborder="0" allowfullscreen></iframe>
</body> 
</html>

Re: Play video links via php?

Posted: Tue Mar 19, 2019 12:25 pm
by Dude
Thanks VB6_to_PBx, but it was the "<?= $file ?>" bit of code that I was missing and needed.