1. Create a H5 <video> tag
<video id= "Sound" type= "Video/mp4" controls= "Controls" autoplay= "AutoPlay" webkit-playsinline= " True " playsinline=" true " heigth=" 100% "></video>
2. Create a request to get the video source and convert the video source to a Blob object
//Create a XMLHttpRequest objectvar xhr =NewXMLHttpRequest (); //Configure request mode, request address, and whether to synchronizeXhr.open (' POST ', '/armystudy/blob/getvideosrc ',true); //Set request result type to BLOBXhr.responsetype = ' blob '; //Request Success callback functionXhr.onload =function (e) {if( This. Status = = 200) {//Request succeeded//Get Blob Objectvar blob = This. Response; //Gets the Blob object address and assigns the value to the container$ ("#sound"). attr ("src"), Url.createobjecturl (BLOB)); } }; Xhr.send ();
3.Java background video to video source
@ResponseBody @RequestMapping ("/getvideosrc") Publicoutputstream getvideosrc (httpservletrequest httpservletrequest, httpservletrespons E httpservletresponse) {//1. Create a File objectFile f =NewFile ("E:/test/1.mp4"); //2. Get the file nameString FileName =F.getname (); //3. Export FilesString Agent = Httpservletrequest.getheader ("User-agent"). toUpperCase (); InputStream FIS=NULL; OutputStream OS=NULL; Try { //4. Get the input streamFIS =NewBufferedinputstream (NewFileInputStream (F.getpath ())); byte[] buffer; Buffer=New byte[Fis.available ()]; Fis.read (buffer); Httpservletresponse.reset (); //5. Because Firefox and other browsers display names differently, different encoding processing is required if(Agent.indexof ("FIREFOX")! =-1) {//Firefox BrowserHttpservletresponse.addheader ("Content-disposition", "attachment;filename=" +NewString (Filename.getbytes ("GB2312"), "Iso-8859-1")); }Else{//Other BrowsersHttpservletresponse.addheader ("Content-disposition", "attachment;filename=" + urlencoder.encode (filename, "UTF-8")); } //6. Set Response encodingHttpservletresponse.setcharacterencoding ("UTF-8"); Httpservletresponse.addheader ("Content-length", "" "+f.length ()); //Set Output file typeHttpservletresponse.setcontenttype ("VIDEO/MPEG4"); //7. Get the response output streamOS =Httpservletresponse.getoutputstream (); Os.flush (); //8. Output Fileos.write (buffer); }Catch(Exception e) {System.out.println (E.getmessage ()); } finally{ //Close the stream Try { if(FIS! =NULL) {fis.close ();} if(OS! =NULL) {Os.flush ();} if(OS! =NULL) {os.close ();} } Catch(IOException e) {System.out.println (E.getmessage ()); } } returnOS; }
Java uses BLOBs to encrypt H5 video playback