如何在jsp数组中一个接一个地播放视频

时间:2014-10-31 03:35:01

标签: html arrays jsp video

我想通过使用数组方法在文件夹名称“video”中按顺序播放视频。但是我只能播放第一个视频。无论如何,我可以在完成第一个视频后更改视频src,这样我就可以一个接一个地播放。谢谢。

<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.io.*" %> 
<%@page import="java.util.*" %> 

<html>
<body>
    <% 
    String DIRECTORY_VIDEO = "video";
    String FolderOriginal = getServletContext().getRealPath("") + File.separator + DIRECTORY_VIDEO;
    File dir = new File(FolderOriginal);
    String[] files = dir.list();    
    int videolength = files.length;
    String newdirectory = DIRECTORY_VIDEO+"/";
    %>
       <video id="myVideo" height="100%" width="100%" controls autoplay">   
         <source id="ss" src="<%=newdirectory+files[0]%>" type='video/mp4'>
       </video>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您是否尝试过向视频添加回调并加载新的视频src?

JSFiddle Link:http://jsfiddle.net/1v9oauru/

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

<script>
$( document ).ready(function() {
    $("#myVideo").bind("ended",function(){
    $("#myVideo source").attr("src","http://techslides.com/demos/sample-videos/small.mp4");
    $("#myVideo")[0].load();
    $("#myVideo")[0].play();
    });
});
</script>
</head>
<body>
<video id="myVideo" width="320" height="240" controls>
  <source src="http://www.w3schools.com/tags/movie.mp4" type="video/mp4">
   Your browser does not support the video tag.
</video>

</body>
</html>

对于视频事件,请参阅以下链接 http://www.w3.org/html/wg/drafts/html/master/embedded-content.html#mediaevents