gpt4 book ai didi

android - 为什么YouTube视频无法在WebView android中播放

转载 作者:行者123 更新时间:2023-12-03 06:14:58 24 4
gpt4 key购买 nike

我在android中有简单的webView,我想通过URL在其中播放视频。
但显示错误的视频无法在网络 View 中播放。
this error is coming while playing

这是我的源代码:-

WebView webView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.livepage);
//Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_bottom7);
webView = (WebView)findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
webView.loadUrl("https://www.youtube.com/channel/UCLmI8_hVUqA251PzK7OSvQw");
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new loadWebView());
}

private class loadWebView extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
}

这是最明显的:-
<application
...
android:supportsRtl="true"
android:largeHeap="true"
android:hardwareAccelerated="true">

提前致谢

最佳答案

根据您的问题,您尚未添加youtube视频链接。您正在使用YouTube channel 网址。无论如何尝试。它运作良好。

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

String frameVideo = "<html><body><iframe width=\"420\" height=\"315\" src=\"https://www.youtube.com/embed/PMBcMBhsm80\" frameborder=\"0\" allowfullscreen></iframe></body></html>";

WebView displayYoutubeVideo = (WebView) findViewById(R.id.mWebView);
displayYoutubeVideo.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
WebSettings webSettings = displayYoutubeVideo.getSettings();
webSettings.setJavaScriptEnabled(true);
displayYoutubeVideo.loadData(frameVideo, "text/html", "utf-8");
}

关于android - 为什么YouTube视频无法在WebView android中播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45273458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com