4
votes

i am building an Android app that need to Stream video from Google drive the video link is like that : https:// docs.google.com/file/d/--ID--

i can't get the rtsp so it can't run the video in a videoview and it doesn't end with mp4 or 3gp... so i can't run it like that :

Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("https:// docs.google.com/file/d/--ID--"), "video/mp4"); view.getContext().startActivity(intent);

i was able to run the video in webView using this code :

webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setPluginState(WebSettings.PluginState.ON); webview.loadUrl("https:// docs.google.com/file/d/--ID--");

webview.setWebChromeClient(new WebChromeClient());

but the video can't be played full screen and it can't be paused and it lag ...

so what should i do ? is there anyway to stream the video from Google drive

1
Is just downloading the file an option? Download it and send an intent to start it with a video player app. If your video format is not supported by VideoView, then that's not an option. You can use players like ExoPlayer, but you'll have to significantly change your implementation as you can't just pass a Drive url to it.Andy
i want to stream the video without downloading the file when i tried to stream the video in computer browser i was able to get a direct link that i could send to an intent to start it with a video player app <div class="html5-video-container"> <video class="video-stream html5-main-video" src="r17---sn-hpa7ln7s.c.docs.google.com/videoplayba...."> </video> </div> but the problem this link appear in page html source only when i click play buttonxochn

1 Answers

4
votes

As I am trying this also and I can find a solution by myself

1: make sure video url is https://drive.google.com/file/d/VIDEO-ID/preview"

2: I download web content from the above url and get direct video url:

public String downloadUrl(String myurl) throws IOException {
        InputStream is = null;
        try {
            URL url = new URL(myurl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setReadTimeout(10000);
            conn.setConnectTimeout(15000);
            conn.setRequestMethod("GET");
            conn.setDoInput(true);
            conn.connect();
            is = conn.getInputStream();
            String contentAsString = readIt(is);
            return contentAsString;
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }

//Get direct video url from stream output

public String readIt(InputStream stream) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            if (line.contains("fmt_stream_map")) {
                sb.append(line + "\n");
                break;
            }
        }
        reader.close();
        String result = decode(sb.toString());
        String[] url = result.split("\\|");
        return url[1]; 
    }

//We need a function to decode url to normal use

public String decode(String in) {
        String working = in;
        int index;
        index = working.indexOf("\\u");
        while (index > -1) {
            int length = working.length();
            if (index > (length - 6)) break;
            int numStart = index + 2;
            int numFinish = numStart + 4;
            String substring = working.substring(numStart, numFinish);
            int number = Integer.parseInt(substring, 16);
            String stringStart = working.substring(0, index);
            String stringEnd = working.substring(numFinish);
            working = stringStart + ((char) number) + stringEnd;
            index = working.indexOf("\\u");
        }
        return working;
    }

After i use thes three function now I can get a direct video url that return by readtIt(InputStream stream) as a string and I can use it for parsing to VideoView.