3

Showing Video on Android Webview. Video getting black while playing and sound occurred but video screen getting black. I am working on android 15+ versions. what is needed to play this?

Fragment_video.xml File

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="children.apps.Fragment.FragmentVideo">


    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webVideoView"
        />

</FrameLayout>

Java Class

public class FragmentVideo extends Fragment {


    public FragmentVideo() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        WebView webView;
        View view = inflater.inflate(R.layout.fragment_video,container,false);

        //ArrayList<String> result = new ArrayList<String>();

        webView = (WebView) view.findViewById(R.id.webVideoView);
        webView.getSettings().setJavaScriptEnabled(true);
        WebSettings ws = webView.getSettings();
        ws.setPluginState(WebSettings.PluginState.ON);
        ws.setJavaScriptEnabled(true);
        webView.setWebChromeClient(new WebChromeClient()
          {
         @Override
            public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)
            {
                    // what to write
            }
            @Override
            public void onHideCustomView(){

        }
            @Override
            public View getVideoLoadingProgressView()
            {

                return null;
            }

        });

        String htmlhead = "<html><head></head><body>";
        String htmlbody = "";

        htmlbody += "<div class=\"video-shortcode\"><iframe title=\"YouTube video player\" width=\"300\"" +
                "height=\"200\" src=\"https://www.youtube.com/embed/HXrcUyCVA6c\"" +
                "frameborder=\"0\" allowfullscreen></iframe></div>";

        String htmlfoot = "</body></html>";
        String html = htmlhead+htmlbody+htmlfoot;
        webView.loadData(html, "text/html","utf-8");
        return view;
    }


}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.