Today found Mu class network video playback address using the Blob encryption. This is a new use, I first discovered. So it will study a little usage.
Blob can we live using fuzzy to some extent. For example, the following play this address:
blob:http://simpl.info/884da595-7816-4211-b6c3-607c444556ef
BLOB (binary large object), binary large object, a container can store binary files. Video blob before and after using binary streams need to support both ends.
Java binary stream generated Blob
-
/*
-
* 在这里可以进行权限验证等操作
-
*/
-
//创建文件对象
-
File f = new File("E:\\test.mp4");
-
//获取文件名称
-
String fileName = f.getName();
-
//导出文件
-
String agent = getRequest().getHeader("User-Agent").toUpperCase();
-
InputStream fis = null;
-
OutputStream os = null;
-
try {
-
fis = new BufferedInputStream(new FileInputStream(f.getPath()));
-
byte[] buffer;
-
buffer = new byte[fis.available()];
-
fis.read(buffer);
-
getResponse().reset();
-
//由于火狐和其他浏览器显示名称的方式不相同,需要进行不同的编码处理
-
if(agent.indexOf("FIREFOX") != -1){//火狐浏览器
-
getResponse().addHeader("Content-Disposition", "attachment;filename="+ new String(fileName.getBytes("GB2312"),"ISO-8859-1"));
-
}else{//其他浏览器
-
getResponse().addHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(fileName, "UTF-8"));
-
}
-
//设置response编码
-
getResponse().setCharacterEncoding("UTF-8");
-
getResponse().addHeader("Content-Length", "" + f.length());
-
//设置输出文件类型
-
getResponse().setContentType("video/mpeg4");
-
//获取response输出流
-
os = getResponse().getOutputStream();
-
// 输出文件
-
os.write(buffer);
-
}catch(Exception e){
-
System.out.println(e.getMessage());
-
} finally{
-
//关闭流
-
try {
-
if(fis != null){
-
fis.close();
-
}
-
} catch (IOException e) {
-
System.out.println(e.getMessage());
-
} finally{
-
try {
-
if(os != null){
-
os.flush();
-
}
-
} catch (IOException e) {
-
System.out.println(e.getMessage());
-
} finally{
-
try {
-
if(os != null){
-
os.close();
-
}
-
} catch (IOException e) {
-
System.out.println(e.getMessage());
-
}
-
}
-
}
-
}
HTML5 Video Use Blob
-
//创建XMLHttpRequest对象
-
var xhr = new XMLHttpRequest();
-
//配置请求方式、请求地址以及是否同步
-
xhr.open('POST', './play', true);
-
//设置请求结果类型为blob
-
xhr.responseType = 'blob';
-
//请求成功回调函数
-
xhr.onload = function(e) {
-
if (this.status == 200) {//请求成功
-
//获取blob对象
-
var blob = this.response;
-
//获取blob对象地址,并把值赋给容器
-
$("#sound").attr("src", URL.createObjectURL(blob));
-
}
-
};
-
xhr.send();
HTML code:
1 |
|
Reprinted from amateur grass: https://www.xttblog.com/?p=1587