我试图从控制器传递视频字节,然后在jsp上读取和播放。它适用于大小小于1 MB MB的视频,但不适用于大于1 MB的文件。请帮我.. 这是我的控制器,它读取文件并将字节写入输出流。
@RequestMapping(value = "/playVideo", method = RequestMethod.GET)
@ResponseBody
public void home(Locale locale, Model model,HttpServletRequest request,HttpServletResponse response) throws IOException {
logger.info("Welcome home! The client locale is {}.", locale);
String filePath = "D://Uploads//s.mp4";
int fileSize = (int) new File(filePath).length();
response.setContentLength(fileSize);
response.setContentType("video");
FileInputStream inputStream = new FileInputStream(filePath);
ServletOutputStream outputStream = response.getOutputStream();
int value = IOUtils.copy(inputStream, outputStream);
System.out.println("File Size :: "+fileSize);
System.out.println("Copied Bytes :: "+value);
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
response.setStatus(HttpServletResponse.SC_OK);
}
这是我的jsp页面
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<video width="320" height="240" controls>
<source src="/elearningportal/playVideo" type=video/mp4>
</video>
</body>
</html>
答案 0 :(得分:0)
您是否尝试使用更大的BufferSize?
response.setBufferSize(fileSize);