1

I developed a PHP script to show a video at a time from an array of videos URL stored in MySQL. It comes out that all the video show at a time. I need to make it show one-by-one. I understand it has to be something with 'onended' html5 event. But I'm not sure how to use it. Has been googling around last 3 days tried many scripts but still couldn't find the solution.

<?php
    $host="localhost";
    $username="root";
    $password="mypass";
    $db_name="mydb";
    $con=mysqli_connect($host, $username, $password);


    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    mysqli_select_db($con, $db_name);
    $vid_url = "/files/";
    $host = $_SERVER['HTTP_HOST'];
    $temp_directory = "/afrison";
    $result = mysqli_query($con,"SELECT fileV FROM m_video limit 1");

    while($row = mysqli_fetch_assoc($result))
    {
        $file=explode("/",$row["fileV"]);
        $file2=explode('"',$file[1]);
        $video = $vid_url.$file2[0];
        $extension = explode(".",$video);
        $type = $extension[1];
        $url = "http://".$host.$temp_directory.$video;

        echo "<br>".$file2[0]."<br>".$video."<br>".$type."<br>".$url." 
              <br>";
        ?>
  <html>
    <body>
        <video id="myVideo" width="320" height="240" controls autoplay 
                   onended="myFunction()">
            <source src="<?php echo $url; ?>" type="video/<?php echo 
             $type; ?>">
                  Your browser does not support the video tag.
        </video>

        <script>

         function myFunction() {
                    window.alert("Some code to play next Video...");
                }

        </script>
</body>
</html>

<?php
    }
?>
  • the onended event is javascript, so have a look at https://stackoverflow.com/questions/14382551/add-a-div-to-replace-video-after-video-plays-through/14387179#14387179 to see how to do things when the triggers. you probably want to return all the videos from your mySQL query into a javascript array and work through that – Offbeatmammal Nov 04 '18 at 09:39

1 Answers1

0

You could create a function inside the php file, and when "controls autoplay onended" is requested, you return the next video, I'm also learning php, I hope this helps you for think in something.

I believe these documentations can help you:

PHP Functions

Call PHP functions with Js

Lima
  • 19
  • 6