0

Below code works if I write it in a simple .html file but it doesn't work from .xhtml. I've read about this and I think that code must work properly because HTML5 is indepent but really video isn't showed.

HTML file and XHTML file share the same code with the difference html show video and xhtml not

Project use Spring 4, Spring WeFlow 2.4, JSF 2.2 and Primefaces 5

From console I get this error:

Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:8080/home/rafa/aio_data/28/videos/V1/video_cE9GTCb7Sh.mp4 

Obviously, file is on my laptop but it's a external resource outside project folders. So, I need something like file:///home/rafa/Desktop/video.html what is displayed on simple HTML5

Anyone know display it?

<video width="320" height="240" controls>
     <source src="/home/rafa/aio_data/28/videos/V1/video_cE9GTCb7Sh.mp4" type="video/mp4">
</video>

HTML created by server

<div id="videoContainer" class="videoContainer">
<ui:repeat>
    <video width="320" height="240">
        <source src="/home/rafa/aio_data/28/videos/V1/video_cE9GTCb7Sh.mp4" type="video/mp4">
    </video>
</ui:repeat>
</div>

Edit: I've tried to show it using Webservlet because I could display picture using p:graphicImage, but this way was failed. A black box is showed even though webservlet catch properly the file.

Webservlet

@WebServlet("/video/*")
public class VideoServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    ServletContext sc=getServletContext();

    String multimediaPath=sc.getInitParameter("multimediaPath");
    String filename=request.getPathInfo().substring(1);

        File file=new File(multimediaPath, filename);



        if(file.exists() && file.isFile()){
            response.setHeader("Content-Type", getServletContext().getMimeType(filename));
            response.setHeader("Content-Length", String.valueOf(file.length()));
            response.setHeader("Content-Disposition", "inline; filename=\"" + filename + "\"");

            //Preventing browser image cache
            response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
            response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
            response.setDateHeader("Expires", 0); // Proxies.

            Files.copy(file.toPath(),response.getOutputStream() );
        }else{
            //ARREGLAR
        }
    //}
}
}

New HTML video tag

<video width="320" height="240">
    <source src="#{request.requestURL.substring(0, request.requestURL.length() - request.requestURI.length())}#{request.contextPath}/video/#{selectedSpace.idSpace}/videos/V1/video_cE9GTCb7Sh.mp4" type="video/mp4" />
</video>
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
  • Post the surrounding source. Also inspect the html that's rendered in the browser to see what gets to the client – kolossus Jan 30 '15 at 06:04
  • @kolossus I added new code and console log. Thanks! – Rafael Ruiz Tabares Jan 30 '15 at 10:31
  • @BalusC that's true! I didn't think about this, thanks :) I display pictures through webservlet and p:graphicImage...but I try doing the same fo video tag but I'm afraid that it's a wrong way for src attribute. I'm going to update the code with webservlet code. – Rafael Ruiz Tabares Jan 30 '15 at 12:22
  • I was searching wrong keys to get the answer. I chose to create a virtual host on glassfish using theses post too http://stackoverflow.com/questions/4543936/load-images-from-outside-of-webapps-webcontext-deploy-folder-using-hgraphi/4543951#4543951 and http://stackoverflow.com/questions/19139426/how-to-write-a-file-to-resource-images-folder-of-the-app/19142316#19142316 . Although I would like to control multimedia files so I must learn to display videos with servlet. Thanks @BalusC – Rafael Ruiz Tabares Feb 01 '15 at 15:03

0 Answers0