Play a youtube url in android

前端 未结 2 1919
孤街浪徒
孤街浪徒 2021-01-25 00:45

I have a fragment and a videoview is present inside that fragment.I have a you tube url for video. I tried videoview as well as webview. But it is not working. How i should play

相关标签:
2条回答
  • 2021-01-25 01:11

    You should use the YouTube Android Player API

    It provides you with an efficient YouTube Player view (or even better - a Fragment) for embedding in your app that you can control programatically.

    0 讨论(0)
  • 2021-01-25 01:14

    Just use normal a webview and everything will be fine.

    Try this: (Tested and works)

    new Thread(new Runnable() {
        @Override
        public void run() {
            final WebView myWebView = (WebView) findViewById(R.id.webView1);
            myWebView.setWebViewClient(new WebViewClient());
            myWebView.getSettings().setJavaScriptEnabled(true);
            myWebView.setWebChromeClient(new WebChromeClient());
    
            try {
                Log.e("Status", "tried url");
                myWebView.loadUrl("http://youtube.com/xxxxxxxxx");  
    
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        Log.e("Status", "In Run():");
                    }
                });
    
            } catch (Exception e) {
                e.printStackTrace();
                Log.e("Status", "exception");
            }       
        }       
    }).start();
    
    0 讨论(0)
提交回复
热议问题