Android - Is it possible to play videos in a WebView?

1

I'm developing a browser for android with java. It works entirely through WebViews. But the app is not able to play videos via stream ... I wonder if it's possible to get it done. Thank you.

WebView in xml:

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

Java code:

WebView wv = (WebView)findViewById(R.id.wv);
wv.setWebViewClient(new WebViewClient());
wv.setJavaScriptEnabled(true);
wv.loadUrl("https://example.com");
    
asked by anonymous 29.04.2018 / 16:38

1 answer

0
public CustomViewCallback mCustomViewCallback;

@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
    super.onShowCustomView(view, callback);
    if (view instanceof FrameLayout) {
        FrameLayout customViewContainer = (FrameLayout) view;
        mCustomViewCallback = callback;
        if (customViewContainer.getFocusedChild() instanceof VideoView) {
            VideoView customVideoView = (VideoView) customViewContainer.getFocusedChild();
            try {
                Field mUriField = VideoView.class.getDeclaredField("mUri");
                mUriField.setAccessible(true);
                Uri uri = (Uri) mUriField.get(customVideoView);
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(uri, "video/*");
                mActivity.startActivity(intent);
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        mCustomViewCallback.onCustomViewHidden();
                    }
                });
            } catch (Exception e) {
            }
        }
    }
}

Font

    
30.04.2018 / 19:00