Skip to content Skip to sidebar Skip to footer

Read Quicktime Movie From Servlet In A Webpage?

I have a servlet that construct response to a media file request by reading the file from server: File uploadFile = new File('C:\\TEMP\\movie.mov'); FileInputStream in = new Fil

Solution 1:

To start, it is firing a GET request, but the servlet is listening on POST requests only. You need to do this task in the doGet() method rather than doPost().

You also need to instruct the webbrowser what information exactly you're sending. This is to be done with the HTTP Content-Type header. You can find here an overview of the most used content types (mime types). You can use HttpServletResponse#setContentType() to set it. In case of Quicktime .mov files, the content type ought to be video/quicktime.

response.setContentType("video/quicktime");

Further, every media format has its own way of being embedded using the <embed> and/or the <object> element. You need to consult the documentation of the media format vendor for details how to use it. In case of Quicktime .mov files, you need to consult Apple. Carefully read this document. It is well written and it handles crossbrowser inconsitenties as well. You would likely prefer to Do It the Easy Way with help of a simple JavaScript to bridge crossbrowser inconsitenties transparently.

<scriptsrc="AC_QuickTime.js"language="javascript"></script><scriptlanguage="javascript">QT_WriteOBJECT('movies/filename.mov' , '320', '240' , '');
</script>

That said, the posted servlet code is honestly said terrible written. Apart from the doPost() incorrectly been used, the IO resource handling is incorrect, every line has its own try/catch, exceptions are been suppressed and poor information is written to stdout, InputStream#available() is been misunderstood, the DataOutputStream is been used for no clear reason, the InputStream is never been closed, etcetera. No, that is certainly not the way. Please consult the basic Java IO and basic Java Exception tutorials to learn more about using them properly. Here's a slight rewrite how the servlet ought to look like:

protectedvoiddoGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
    Stringfilename= URLDecoder.decode(request.getPathInfo(), "UTF-8");
    Filefile=newFile("/path/to/all/movies", filename);

    response.setHeader("Content-Type", "video/quicktime");
    response.setHeader("Content-Length", file.length());
    response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");

    BufferedInputStreaminput=null;
    BufferedOutputStreamoutput=null;

    try {
        input = newBufferedInputStream(newFileInputStream(file));
        output = newBufferedOutputStream(response.getOutputStream());

        byte[] buffer = newbyte[8192];
        for (intlength=0; (length = input.read(buffer)) > 0;) {
            output.write(buffer, 0, length);
        }
    } finally {
        if (output != null) try { output.close(); } catch (IOException logOrIgnore) {}
        if (input != null) try { input.close(); } catch (IOException logOrIgnore) {}
    }
}

Map it in web.xml as follows:

<servlet><servlet-name>movieServlet</servlet-name><servlet-class>com.example.MovieServlet</servlet-class></servlet><servlet-mapping><servlet-name>movieServlet</servlet-name><url-pattern>/movies/*</url-pattern></servlet-mapping>

The aforeposted JavaScript example shows exactly how you should use it. Just use path /movies and append the filename thereafter like so /movies/filename.mov. The request.getPathInfo() will return /filename.mov.

Solution 2:

<EMBEDSRC="<your servlet hosting the movie>"WIDTH=100HEIGHT = 196AUTOPLAY=trueCONTROLLER=trueLOOP=falsePLUGINSPAGE=http://www.apple.com/quicktime/">

Solution 3:

The most widely supported way would be to embed a flash player (swf) and return a FLV file from your program. Flash will automatically stream the flv file.

http://snipplr.com/view/288/flash-video-player-html-code/

Post a Comment for "Read Quicktime Movie From Servlet In A Webpage?"