那么,我不打算为你写整个幻灯片。但是,下面是如何在文件夹中将电影列为链接并在点击它们时将它们添加到视频源属性的示例。在这个例子中,我们假设我们将所有的脚本添加到同一个文件中。
此脚本
要求的工作:
HTML
把你的身体标记之间按照您的index.php
<!-- this is your video element -->
<video width="400" controls>
<!-- your video source, verify so that type is accurate -->
<source id="vidsrc" src="myvideo.mp4" type="video/mp4">
</video>
PHP
把下面的脚本某处你的身体标记之间的index.php文件
<?php
//fetch and list all the files found in the video folder. Make sure to change the path to your video folder.
foreach(glob('path-to-your-video-folder/*') as $video){
echo '- <a href="#" class="isVideo" data-video="'.$video.'">'.$video.'</a><br/>';
}
?>
jQuery的
把下面的脚本的底部,你的身体结束标记之前。
<script type="text/javascript">
//jQuery code that will trigger when you click on one of the links displayed by the PHP script
$('.isVideo').on('click',function(){
//this will change the video source to the chosen video
$('#vidsrc').attr('src',$(this).data('video'));
return false;
});
</script>
嗨entiendo我无法理解我要做什么与你的代码片段 –
嗨,我更新了我的帖子,更多的信息。请让我知道你是否有问题。 – entiendoNull
嗨entiendo我添加了我的视频的位置是在媒体中,他们显示为链接,但视频播放器显示无效的来源。如果php或jquery没有用视频填充视频播放器。 –