简体   繁体   中英

Play video from Folder

I am trying to make a simple streaming site. That will pay a video from a folder. (mp4). The tricky part is I want to change the video everyday but not the code. So Im wondering if I can use some jquery or php for a global call to look in the folder find the file by the ext and play it.

So essentially instead of renaming the video or changing the codes specific path, I can just change the file thats in the folder, and refresh the page.

What I have so far

Try something like this, assuming there is only one video with the given extension in said folder (otherwise it will get the last occurring file with that extension):

$myVideoDir = '/videos';
$extension = 'mp4';
$videoFile = false;
foreach(scandir($myVideoDir) as $item) {
    if ( $item != '..' && $item != '.' && !is_dir($item) ) {
        $ext = preg_replace('#^.*\.([a-zA-Z0-9]+)$#', '$1', $item);
        if ( $ext == $extension )
            $videoFile = $item;
    }
}

if ( !!$videoFile ) {
    echo '
        <video id="dep" class="center" width="900" height="720" controls>        
          <source src="'.$myVideoDir.'/'.$videoFile.'" type="video/mp4"> 
        </video>
    ';
}
$myVideoDir = '/videos';
$extension = 'mp4';
$videoFile = false;
foreach(scandir($myVideoDir) as $item) {
    if ($item != '..' && $item != '.' && !is_dir($item)) {
        $ext = preg_replace('#^.*\.([a-zA-Z0-9]+)$#', '$1', $item);
        if ($ext == $extension) $videoFile = $item;
    }
}
if (!!$videoFile) {
    echo ' <video id="dep" class="center" width="900" height="720" controls> <source src="'.$myVideoDir.
    '/'.$videoFile.
    '" type="video/mp4"> </video> ';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM