3

Possible Duplicate:
How to stream MP3 to HTML5 PLAYER such as Accessible Audio Player

I'm developing a Java solution to perform a MP4 video delivery for a HTML5 page. The solution checks if the user it's logged and if it's then start to deliver the video to the user.

My code works properly on my laptop with Eclipse Indigo and Tomcat 6 and I can play without problem the video, but when I deliver it in a WAR file to my production server (Tomcat 6+Debian) I'm unable to play the video on my navigator (Google Chrome). If I check the headers through the Developer Mode of Chrome I see that It's all ok and we can see in "Network tab" that the video it's downloading from the server but it doesn't appears on the window.

The code of my servlet it's the following:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
    HttpSession sesion = request.getSession();      
    try
    {
        Integer idUsuario = (Integer) sesion.getAttribute("ID_USUARIO");
        Integer vID = Integer.parseInt((String) request.getParameter("vID"));
        if (idUsuario != null && idUsuario > 0 && vID != null && vID > 0)
        {
            VideoService servVideo = new VideoService();
            TipoVideo video = new TipoVideo();
            video = servVideo.obtieneVideo(vID);
            String ruta = "/home/video/vod/";
            String[] litVideo = video.getLiteralVideo().split(":");
            if (litVideo.length > 1)
            {
                ruta = ruta.concat(litVideo[1]);
            }
            else
            {
                ruta = ruta.concat(litVideo[0]);
            }
            if (ruta != null && !ruta.isEmpty() && ruta.length()>2)
            {   
                java.io.File fichero = new java.io.File(ruta);
                java.io.FileInputStream fileInputStream = new java.io.FileInputStream(fichero);                 
                response.setContentType("video/mp4");   
                response.setHeader("Content-Length", Long.toString(fichero.length()));
                log("Antes: " + Long.toString(fichero.length()));
                response.setContentLength(Integer.parseInt(Long.toString(fichero.length())));
                log("Pasamos la petición");
                ServletOutputStream op = response.getOutputStream();
                int i;
                while ((i=fileInputStream.read()) != -1) 
                {
                 //out.write(i);
                    op.write(i);
                }       
                fileInputStream.close();
                op.flush();
                op.close();
                return; 
            }
        }
        else
        {
            response.getWriter().println("ACCESO DENEGADO");
            log("Acceso denegado");
        }
    }
    catch (NumberFormatException nfex)
    {
        response.getWriter().println("nfex: " + nfex.getMessage());
        log("nfex: " + nfex.getMessage());          
    }
    catch (ServicioException servEx)
    {
        response.getWriter().println("servEx: " + servEx.getMessage());
        log("servEx: " + servEx.getMessage());
    }
    catch (Exception ex)
    {
        response.getWriter().println("Excepción: " + ex.getMessage());
        log("Excepción: " + ex.getMessage());
    }
       }

In my production server I've the default tomcat 6 configuration. No other application or web server it's installed on the machine.

Anyone have any idea of what's it's failing here or how I can fix it?

Community
  • 1
  • 1
ramon
  • 31
  • 4
  • Hi BalusC, I've checked the the other topic and I follow your tutorial. With that I've reached the goal of being able to play the video, but with a extremly high number of request (more than 3000 GET request for a 720p and no more than 1:30 min video) and extremly slow (my server has 100mbit internet connection at the datacenter and I've a FTTH connection of 50mbit). I'll try to understand better your tutorial and improve your solution for my needs. Thank you! – ramon Dec 18 '12 at 23:23
  • Isn't this what a CDN is for? – Christopher Schultz Dec 19 '12 at 17:45

0 Answers0