播放文件夹中的视频 [英] Play video from Folder
问题描述
我正在尝试制作一个简单的流媒体网站.这将支付来自文件夹的视频. (mp4).棘手的部分是我想每天更改视频,而不是代码.所以我想知道我是否可以使用一些jquery或php进行全局调用以查看文件夹中的ext文件并播放它.
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.
推荐答案
尝试类似的操作,假设在所述文件夹中只有一个视频具有给定扩展名(否则它将获得具有该扩展名的最后一个文件):
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>
';
}
这篇关于播放文件夹中的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!