生活随笔
收集整理的這篇文章主要介紹了
视频播放测试
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//視頻播放測試
public String text(HttpServletRequest re, HttpServletResponse rs) {
CloseableHttpClient httpClient = null;
try {SSLContext sslContext = SSLContextBuilder.create().useProtocol(SSLConnectionSocketFactory.SSL).loadTrustMaterial((x, y) -> true).build();RequestConfig config = RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).build();httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).setSSLContext(sslContext).setSSLHostnameVerifier((x, y) -> true).build();} catch (Exception e) {e.printStackTrace();}String flag = "0";HttpGet httpGet = new HttpGet("*******");httpGet.setHeader(new BasicHeader("Cookie", "******"));// response 對象CloseableHttpResponse response = null;try {response = httpClient.execute(httpGet);// 判斷返回狀態是否為200if (response.getStatusLine().getStatusCode() == 200) {HttpEntity entity = response.getEntity();InputStream in=entity.getContent(); int count = 0; while (count == 0) { count = Integer.parseInt(""+entity.getContentLength());//in.available(); } byte[] bytes = new byte[count]; int readCount = 0; // 已經成功讀取的字節的個數 while (readCount <= count) { if(readCount == count)break; readCount += in.read(bytes, readCount, count - readCount); } OutputStream out=null;rs.setContentType("video/mp4");out = rs.getOutputStream();out.write(bytes);out.flush();out.close();}} catch (ClientProtocolException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally {if (null != httpGet) {httpGet.releaseConnection();}if (null != response) {try {response.close();} catch (IOException e) {}}}return flag; }
總結
以上是生活随笔為你收集整理的视频播放测试的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。