logcat logcat - 5 months ago 39
PHP Question

How to display video one after another from Database in HTML5

I have a video table which contains (more than one) id and video_path. I want to play video one after another from the database using PHP in HTML5. note that I keep only video path in the table.

I am trying

PHP

$connection...
while($row = mysqli_fetch_assoc($controller)) {
$id = $row['id'];
$url = $row['video_path'];
$vdo = $_POST[$url];
}


HTML

<video id="custom_video_play" width="400" controls="controls" src="$vdo" autoplay="autoplay" loop>
</video>


my database query is working properly. I want to fix the code error only to watch video in web page.
if someone please help!
Thanks in advance

Answer

You can recursively call a play function which checks if the current video has ended, if it has it will get the next src path in your array.

    // Get the video of the element
    var video = $('#your_video_elem');
    var video_array; // get your array of video paths
    var n = 0;

    $(document).ready(function(){
         // Check if DOM is ready, if so play the first video.
        play_video();
    });

    function play_video() {
        if(video.get(0).ended) {
            video.attr('src', video_array[n]);
            n++;
            play_video();    // call recursively to get the next video
        } 
    }

The play_video method is called recursively only one the current video has ended, it loops through your array of video paths and updates the src of your video tag each time

Comments