java播放视频通过断点续传拖动滚动条
java播放视频如果需要后台处理,并不是请求xxx.mp4.当需要拖动进度条的时候部分浏览器是不行的,这里就需要断点续传。
直接上代码,通过video的src请求
/**
* video请求位置
*
* @param request
* @param response
*/
@RequestMapping(value = "/player", method = RequestMethod.GET)
public void player2(HttpServletRequest request, HttpServletResponse response) {
String path = request.getServletContext().getRealPath("/static/my/video/interview.mp4");
BufferedInputStream bis = null;
try {
File file = new File(path);
if (file.exists()) {
long p = 0L;
long toLength = 0L;
long contentLength = 0L;
int rangeSwitch = 0; // 0,从头开始的全文下载;1,从某字节开始的下载(bytes=27000-);2,从某字节开始到某字节结束的下载(bytes=27000-39000)
long fileLength;
String rangBytes = "";
fileLength = file.length();
// get file content
InputStream ins = new File