Back to project page AdvancedPlayer.
The source code is released under:
Apache License
If you think the Android project AdvancedPlayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.huilan.library_videoplay.util; /*from w ww . ja va2s . c o m*/ import android.text.TextUtils; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import java.io.InputStream; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Created by liujigang on 2014/9/30 0030. */ public class ParseHtmlToUrl { /** * ????html ???????????????url */ public String getVideoUrl(String url, String regex) { if (TextUtils.isEmpty(regex)) { return ""; } String content = parseHtml(url); // String regex = "(/eportal/immovableDir/lszrmzf/resource/cms/)(.{0,50})\\.flv"; Pattern pa = Pattern.compile(regex, Pattern.DOTALL); Matcher ma = pa.matcher(content); if (ma.find()) { int endIndex = url.indexOf('/', 9); String group = ma.group(); if (group.startsWith("http")) { return group; } else { String hostUrl = url.substring(0, endIndex == -1 ? url.length() : endIndex); return hostUrl + group; } } else { return ""; } } public String parseHtml(String url) { try { HttpClient getClient = new DefaultHttpClient(); HttpGet request = new HttpGet(url); HttpResponse response = getClient.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { InputStream is = response.getEntity().getContent(); long contentLength = response.getEntity().getContentLength(); if (contentLength > 1024 * 500) {//1024*1024 is.close(); is = null; return ""; } StringBuilder sb = new StringBuilder(); int len; byte[] bytes = new byte[1024]; while ((len = is.read(bytes)) != -1) { sb.append(new String(bytes, 0, len, "utf-8")); if (sb.length() > 1024 * 500) { sb.delete(0, sb.length()); sb = null; return ""; } } is.close(); is = null; return sb.toString(); } else { return ""; } } catch (Exception e) { e.printStackTrace(); } return ""; } }