我试图在android上用webview加载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: Web View Secure Origin
,但无法使其工作,因此我正在android上尝试找出使其工作所需的设置。