Good night everybody. Interested in the question of how to play the video in the browser, while the video is on the local machine.

Who can is joined with such problem what players yuzat? More interested in players on common formats. How to connect them to read the file from the local machine? Already tried to write a servlet which returns a flow, all the same did not help.

package compam.servlets; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import compam.model.Film; import compam.services.FilmService; /** * Servlet implementation class DownloadService */ @WebServlet("/download") public class DownloadFilm extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int id = Integer.parseInt(request.getParameter("id")); Film film = new Film(); film = new FilmService().getFilmById(id); String path = film.getFileLink(); int length = 0; File file = new File(path); ServletOutputStream outputStream = response.getOutputStream(); String mimeType = getServletConfig().getServletContext().getMimeType( path); response.setContentType((mimeType != null) ? mimeType : "application/octet-stream"); response.setContentLength((int) file.length()); response.setHeader("Content-Disposition", "attachment; filename=\"" + film.getName().replace(" ", "_") + "\""); byte[] bbuf = new byte[4096]; DataInputStream in = new DataInputStream(new FileInputStream(file)); while ((in != null) && ((length = in.read(bbuf)) != -1)) { outputStream.write(bbuf, 0, length); } in.close(); outputStream.flush(); outputStream.close(); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } } 

Who knows how to solve this problem? Thanks in advance.

    3 answers 3

    JavaScript players will not suit you?

    • probably arrange, but I just could not tune in to broadcast from localhost - Sergii
    • Um, and what's the difference where the broadcasting through the browser? You need to google on this topic. - DroidAlex

    I’ll say right away that I didn’t come across such a thing, but I was interested in the question. All I can help with so far is streaming audio / video broadcasting from VideoLAN . It also says that you can

    use VideoLAN as a regular media player

    VideoLan website.
    There is also a DivX Browser Plugin , but I didn’t specify whether using this utility you can watch videos from sites or from a computer.

    • thanks, I will look - I will unsubscribe) - Sergii
    • Does not work) - Sergii

    You can try using Vaadin . Like that:

     package com.vaadin.demo.sampler.features.embedded; import com.vaadin.terminal.FileResource; import com.vaadin.ui.Embedded; import com.vaadin.ui.VerticalLayout; @SuppressWarnings("serial") public class FlashEmbedExample extends VerticalLayout { public FlashEmbedExample() { File file = new File("/home/user/file.flv"); Embedded e = new Embedded(null, new FileResource(file, getApplication()); e.setMimeType("application/x-shockwave-flash"); e.setParameter("allowFullScreen", "true"); e.setWidth("320px"); e.setHeight("265px"); addComponent(e); } } 
    • will it support avi, mpeg, mp4 for example? - Sergii pm
    • I think not - iwowa
    • Naturally not, Mimi-type is specified - flash - DroidAlex