Embed Youtube video inside an Android app

后端 未结 9 1483
野性不改
野性不改 2021-01-29 23:01

I\'m using a WebView for displaying embedded Youtube video and that works on Galaxcy S2 (OS 2.3.5) and doesn\'t on Nexus S (OS 2.3.4), all I get is white screen without any vide

9条回答
  •  忘掉有多难
    2021-01-29 23:45

    How it looks:

    Best solution to my case. I need video fit web view size. Use embed youtube link with your video id. Example:

    WebView youtubeWebView; //todo find or bind web view
    String myVideoYoutubeId = "-bvXmLR3Ozc";
    
    outubeWebView.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    return false;
                }
            });
    
    WebSettings webSettings = youtubeWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    
    youtubeWebView.loadUrl("https://www.youtube.com/embed/" + myVideoYoutubeId);
    

    Web view xml code

    
    

提交回复
热议问题