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.