我如何使用Struts2在JSP中播放多个视频 [英] How do i play multiple videos in jsp using struts2

查看:49
本文介绍了我如何使用Struts2在JSP中播放多个视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我曾尝试在jsp页面中播放视频,但该视频获得了成功.如何在jsp中播放多个视频,视频文件在特定的文件夹中(文件系统) 下面是显示一个视频文件的代码

Hi everyone i was tried to play video in jsp page which get success. How do i play multiple videos in jsp, the video files are in specific folder(File system) below is the code to display one video file

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

推荐答案

如果要播放多个视频,则需要多个流.

If you want to play multiple videos, you need multiple streams.

由于动作的流结果表示一个流,因此您需要多个动作.

Since the Stream result of an action represents one stream, you need multiple actions.

例如,您可以对不同的动作进行多次AJAX调用,或者对同一动作进行多次AJAX调用,并将要播放的文件的名称作为参数传递...但是我不明白为什么您应该播放一次播放多个视频.我们有两只眼睛和一只大脑,真的很擅长多任务处理,所以...问题尚不清楚.

For example, you can make many AJAX calls to different actions, or to the same action passing the name of the file you want to play as parameter... but I don't get why on earth you should want to play multiple videos at once. We have two eyes and a brain, and really su*k at multitasking so... the question is not clear.

这篇关于我如何使用Struts2在JSP中播放多个视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆