Click here to Skip to main content
15,843,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to display a google drive video inside a WebView, but if I remove the google drive toolbar, the video never plays.
Can someone please help?
Thanks.

What I have tried:

import android.app.ProgressDialog;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.VideoView;

import androidx.appcompat.widget.Toolbar;

public class video extends base  {
    private Toolbar mtoolbar;
    private String[] videoArray;
    private WebView video;
    private String video_url="https://drive.google.com/open?id=1ThYBj7gG3cwSxYvpbcq-Bu44ezXrn6CK";
    private ProgressDialog pd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
        setTitle("Videos");
        mtoolbar = (androidx.appcompat.widget.Toolbar) findViewById(R.id.toolbar);
        //video = findViewById(R.id.video);
        video=findViewById(R.id.video);
        video.setWebViewClient(new WebViewClient() {

            //once the page is loaded get the html element by class or id and through javascript hide it.
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                video.loadUrl("javascript:(function() { " +
                        "document.getElementsByClassName('ndfHFb-c4YZDc-GSQQnc-LgbsSe ndfHFb-c4YZDc-to915-LgbsSe VIpgJd-TzA9Ye-eEGnhe ndfHFb-c4YZDc-LgbsSe')[0].style.display='none'; })()");
            }
        });
        video.loadUrl(video_url);
        //video.loadUrl(video_url);
    }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900