Iframe Youtube视频使用DialogFragment显示黑屏,并且只有音频在Webview中播放
我正在使用JSON将JSON中的iframe youtube链接数据解析为对话框片段中的Webview.视频输出显示黑屏,并且仅播放视频的音频.我试图在清单文件中以及以编程方式在Java代码中使用(android:hardwareAccelerated ="true"),但它对我不起作用.
I am parsing iframe youtube link data using JSON to Webview in a Dialog Fragment. Video output is showing a black screen and only the audio of the video is playing. I have tried to use (android:hardwareAccelerated="true") in the manifest file and as well as programmatically in java code but it did not work for me.
如果我在活动中使用Same而不是DialogFragment,那么我会得到视频的输出结果,一切对我来说都很好,但是由于某些原因,我只需要在Dialog Fragment中播放youtube视频.如何做到这一点,请帮忙,这是我的下面的代码.
If I use the Same in an Activity instead of a DialogFragment then I am getting the output result of the video and everything is working fine for me but for some reason, I need to play youtube video only in a Dialog Fragment. How to do this please help and here is my code below.
public class Activity extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment, container, false);
String frameVideo = "<html><body>Youtube video .. <br> <iframe width="320" height="315" src="https://www.youtube.com/embed/lY2H2ZP56K4" frameborder="0" allowfullscreen></iframe></body></html>";
WebView mwebView = view.findViewById(R.id.webView);
mwebView.setWebChromeClient(new WebChromeClient() {
});
displayVideo.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
mwebView.getSettings().setAppCachePath(getActivity().getCacheDir().getAbsolutePath());
mwebView.getSettings().setJavaScriptEnabled(true);
mwebView.getSettings().setAllowFileAccess(true);
mwebView.getSettings().setAppCacheEnabled(true);
// mwebView.setInitialScale(1);
// mwebView.getSettings().setUseWideViewPort(true);
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
mwebView.getSettings().setPluginState(WebSettings.PluginState.ON);
}
mwebView.getSettings().setLoadWithOverviewMode(true);
mwebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
mwebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
mwebView.loadData(frameVideo, "text/html", "utf-8");
}
我检查了您的代码,这很好.我评论了 setLayerType
属性并进行了检查.一切正常.只需注释 mwebView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
.
I checked your code and it's fine. I commented setLayerType
property and checked. It's working fine. Just comment mwebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
.