tarek360 / Instacapture

Android library to capture screenshot from your app
694 stars 113 forks source link

Doesn't capture video in WebView #15

Closed mdbnet closed 7 years ago

mdbnet commented 7 years ago

Hi. I was curious if this library could capture an image of a video in a WebView, so I added a "Web View Sample" button to my local copy of the project. This just opens a WebView displaying the YouTube page.

Before I pressed the "Capture" button I just clicked on a movie to start it playing. The screenshot contains the YouTube page, and the video playing controls. But where the video would be it is just black. I also tried another site with videos ("http://www.quirksmode.org/html5/tests/video.html") but with the same results.

Do you think there is a way to capture the video image? If you have any ideas please let me know.

The sample code is below.

package com.tarek360.sample;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import butterknife.BindView;
import butterknife.OnClick;

public class WebViewSampleActivity extends BaseSampleActivity {

  @BindView(R.id.toolbar) Toolbar toolbar;

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view_sample);

    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    WebView webView = (WebView) findViewById(R.id.webView);
    if (webView != null)
    {
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });

        //webView.loadUrl("http://www.quirksmode.org/html5/tests/video.html");
        webView.loadUrl("https://www.youtube.com/");
    }
  }
tarek360 commented 7 years ago

Hi @mdbnet , thank you for reporting this, as you described Instacapture works fine with webView but videos in webView or even in the desktop browsers is rendering in a different way so we can't get a screenshot directly from it, I think you have to find youtube API to get a screenshot from the player.