在webview中查找流媒体视频

时间:2014-07-31 05:16:44

标签: android webview android-webview html5-video

实际上我的目标是实现webview并在webview中捕获流式视频的URL。 我尝试了很多代码但没有结果。到目前为止我的代码我试过了  `

public boolean shouldOverrideUrlLoading(WebView view, String url) {
        System.out.println("link"+url);

        } else if (url.startsWith("http://www.youtube.com")
                || url.startsWith("https://www.youtube.com")
                || url.startsWith("http://m.youtube.com")
                || url.startsWith("https://m.youtube.com")) {
            Intent urlIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(url));
            urlIntent.putExtra(mPackageName + ".Origin", 1);
            mActivity.startActivity(urlIntent);
            return true;


        } else if (url.startsWith("magnet:?")) {
            Intent urlIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(url));
            urlIntent.putExtra(mPackageName + ".Origin", 1);
            mActivity.startActivity(urlIntent);
        } else if (url.startsWith("intent://")) {
            Intent intent = null;
            try {
                intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
            } catch (URISyntaxException ex) {
                return false;
            }
            if (intent != null) {
                try {
                    mActivity.startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    Log.e(Constants.LOGTAG, "ActivityNotFoundException");
                }
                return true;
            }
        }
        return super.shouldOverrideUrlLoading(view, url);
    }
}

1 个答案:

答案 0 :(得分:0)

我找到了一个从网址中提取所有链接的jar可能对你有帮助 基本上有2个罐子

  1. HTML parser

  2. Jsoup

  3. 我在jsoup jar和wriiten的代码下工作:从url中提取了所有链接并给了我现在你可以对它进行排序并得到你有用的网址

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            new AsyncTask().execute();
    
        }
    
        class AsyncTask extends android.os.AsyncTask<Void, Void, Void> {
    
            @Override
            protected Void doInBackground(Void... params) {
                // TODO Auto-generated method stub
                Document doc;
                try {
    
                    // need http protocol
                    doc = Jsoup.connect(
                            "http://video.nationalgeographic.com/").get();
    
                    // get page title
                    String title = doc.title();
                    System.out.println("title : " + title);
    
                    // get all links
                    Elements links = doc.select("a[href]");
                    for (Element link : links) {
    
                        // get the value from href attribute
                        System.out.println("\nlink : " + link.attr("href"));
                        System.out.println("text : " + link.text());
    
                    }
    
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return null;
            }
    
        }
    
    }