大家好我曾尝试在jsp页面播放视频,并获得成功。如何在jsp中播放多个视频,视频文件在特定文件夹中(文件系统) 下面是显示一个视频文件的代码
JSP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<video width="400" controls>
<source src="<s:url value="videoStream" />" type="video/mp4"/>
<source src="mov_bbb.ogg" type="video/ogg">
Your browser does not support HTML5 video.
</video>
</body>
</html>
**struts.xml**
<struts>
<package name="user" namespace="/" extends="struts-default">
<action name="videoStream" class="com.pradeep.videostream.VideoStreamingAction">
<result name="success" type="stream">
<param name="contentType">${yourContentType}</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${yourFileName}"</param>
<param name="bufferSize">1024</param>
</result>
</action>
</package>
</struts>
动作类
public class VideoStreamingAction extends ActionSupport {
private InputStream inputStream;
private String yourContentType;
// getters and setters
public String execute() throws Exception {
yourContentType = "video/mp4";
File file =new File("D://svn videos//Create Java Spring Web MVC Project With Maven [EDITED].mp4");
setInputStream(new ByteArrayInputStream(FileUtils.readFileToByteArray(file)));
return SUCCESS;
}
}
我这样改变了我的jsp
<html>
<body>
<form action="getFiles">
<input type="submit" value="check">
</form>
<s:iterator value="filesList">
<video width="400" controls>
<source src="<s:url value='getFiles.action?fileName='/><s:property/>" type="video/mp4" />
<source src="mov_bbb.ogg" type="video/ogg"> Your browser does not support HTML5 video. </video>
</s:iterator>
</body>
</html>
struts.xml中
<struts>
<package name="user" namespace="/" extends="struts-default">
<action name="getFiles" class="com.pradeep.videostream.VideoStreamingAction">
<result name="success">index.jsp</result>
</action>
<!-- <action name="videoStream" class="com.pradeep.videostream.VideoStreamingAction">
<result name="success" type="stream">
<param name="contentType">${yourContentType}</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${yourFileName}"</param>
<param name="bufferSize">1024</param>
</result>
</action> -->
</package>
</struts>
动作类
public class VideoStreamingAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private InputStream inputStream;
private String yourContentType;
private File[] filesArray = null;
private List<String> filesList = new ArrayList<String>();
//getters and setters
public String execute() throws Exception {
File folder = new File("D://svn videos");
filesArray = folder.listFiles();
for (int i = 0; i < filesArray.length; i++) {
String fileName=filesArray[i].getName();
filesList.add(fileName);
}
HttpServletResponse response = ServletActionContext.getResponse();
HttpServletRequest request = ServletActionContext.getRequest();
String fileName = request.getParameter("fileName");
System.out.println("GGGGGGGGGGGGGGGGG "+fileName);
File file = new File(fileName);
setInputStream(new ByteArrayInputStream(FileUtils.readFileToByteArray(file)));
return SUCCESS;
}
}
答案 0 :(得分:0)
如果您想播放多个视频,则需要多个视频流。
由于操作的Stream结果代表一个流,因此您需要多个操作。
例如,您可以对不同的操作进行多次AJAX调用,或者将相同的操作传递给您要作为参数播放的文件的名称...但我不明白为什么你应该想玩一次多个视频。我们有两只眼睛和一只大脑,而且在多任务处理时真的太棒了......所以问题还不清楚。