Android Web View无法加载Youtube嵌入的视频

时间:2019-02-03 20:03:09

标签: android webview

我正在尝试使用WebView在Android上加载Youtube嵌入式视频,当我尝试加载嵌入式视频时,播放器上没有显示任何视频。

这是我正在玩的示例代码

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    b1 = (Button) findViewById(R.id.button);
    ed1 = (EditText) findViewById(R.id.editText);

    wv1 = (WebView) findViewById(R.id.webView);
    wv1.clearCache(true);
    wv1.setWebViewClient(new MyBrowser());
    wv1.getSettings().setJavaScriptEnabled(true);
    wv1.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    wv1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    wv1.getSettings().setDomStorageEnabled(true);
    wv1.setWebViewClient(new WebViewClient());

    b1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          String url = ed1.getText().toString();
          wv1.getSettings().setLoadsImagesAutomatically(true);
          wv1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
          url = "https://www.youtube.com/embed/vlkNcHDFnGA";
          // In particular I am interested in the above video as it requires HTTPS origin as well

          wv1.loadUrl(url);
        }
    });

我最初是在Flutter Flutter: Web View Secure Origin上尝试此操作,但无法使其正常工作,因此我正在Android上尝试找出可能需要进行哪些设置

0 个答案:

没有答案