39,084
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE>
<html>
<head>
<title> Test </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
<style type="text/css">
input,video{
display: block;
}
</style>
<script type="text/javascript">
function createObjectURL(object) {
return (window.URL) ? window.URL.createObjectURL(object) : window.webkitURL.createObjectURL(object);
}
function play(){
if(this.files.length) {
video.src = (window.URL) ? window.URL.createObjectURL(this.files[0]) : window.webkitURL.createObjectURL(this.files[0]);
}
}
</script>
</head>
<body>
<input type="file" id="file" onchange="play.call(this);"/>
<video controls autoplay id="video" width="320" height="240" controls>
Your browser does not support the video tag.
</video>
</body>
<script>
var video = document.getElementById("video");
</script>
</html>
byte[] data = getBytesFromFile(new File("D:/media/final.mp4"));
String diskfilename = "final.mp4";
response.setContentType("video/mp4");
//response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=\"" + diskfilename + "\"" );
System.out.println("data.length " + data.length);
response.setContentLength(data.length);
response.setHeader("Content-Range", range + Integer.valueOf(data.length-1));
response.setHeader("Accept-Ranges", "bytes");
response.setHeader("Etag", "W/\"9767057-1323779115364\"");
byte[] content = new byte[1024];
BufferedInputStream is = new BufferedInputStream(new ByteArrayInputStream(data));
OutputStream os = response.getOutputStream();
while (is.read(content) != -1) {
os.write(content);
}
is.close();
os.close();