简体   繁体   English

播放文件夹中的视频

[英]Play video from Folder

I am trying to make a simple streaming site.我正在尝试制作一个简单的流媒体网站。 That will pay a video from a folder.这将从文件夹中支付视频。 (mp4). (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.所以我想知道我是否可以使用一些 jquery 或 php 进行全局调用,以查看文件夹中的 ext 文件并播放它。

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> ';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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