以视频的截图在网页视图的android [英] Take a screenshot of a video in a webview android

查看:189
本文介绍了以视频的截图在网页视图的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个项目,我保存的截图中的WebView。 API级别是21.在它工作绝对没一个正常的网页,但是当我访问YouTube,观看视频,视频播放器的回报为黑色矩形。
我想要做的就是当用户触摸屏幕截图。

I am working on a project where I save a screenshot in a WebView. API Level is 21. On a normal homepage it works absolutely fine, but when I visit youtube and watch a video, the video player returns as a black rectangle. What I want to do is take a screenshot whenever the user touches the screen.

当我随身携带电源和功放的截图;音量按钮它完美。是否有这需要这样的一个屏幕截图的意图是什么?理想情况下,截图将只包含web视图,但如果它的整个屏幕,我可以,太多的工作。

When I take a screenshot with Power & Volume Button it works perfectly. Is there an Intent which takes this kind of a screenshot? Ideally the screenshot would only contain the webview, but if it's the entire screen I can work with that too.

任何帮助是极大AP preciated。

Any help is greatly appreciated.

干杯,

托比

编辑:我的一些code的

some of my code

View rootView;
ValueCallback<String> callback = new ValueCallback<String>() {
    @Override
    public void onReceiveValue(String value) {
        category1.setText(value);
    }
};
String root = android.os.Environment.getExternalStoragePublicDirectory
        (Environment.DIRECTORY_DCIM).toString(), filename, time, puretime, movementType = ""; //movementType is set according to MotionEvent.getAction()
File myDir = new File(root + "/saved_files/")

protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);

    rootView = findViewById(android.R.id.content).getRootView();
    rootView.setDrawingCacheEnabled(true);
}

public class MyView extends View {
    public MyView(Context context) {
        super(context);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        calendar = Calendar.getInstance();
        time = String.format("%02d:%02d:%02d.%03d", calendar.get(Calendar.HOUR_OF_DAY),
                calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND),
                calendar.get(Calendar.MILLISECOND));
        puretime = String.format("%02d%02d%02d%03d", calendar.get(Calendar.HOUR_OF_DAY),
                calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND),
                calendar.get(Calendar.MILLISECOND));
        if (movementType.equals("down")) {
            try {
                filename = puretime + ".xml";
                webView.saveWebArchive(myDir+filename, false, callback);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        invalidate();
        return true;
    }

EDIT2:

显然为黑色矩形的问题在于元件作为视频由GPU和一个正常的快照工作方案将需要计算每帧是太多的工作进行处理。

apparently the problem for the black rectangles is that elements as the video are processed by the gpu and for a "normal" snapshot to work the program would need to calculate every frame which is too much work.

推荐答案

我认为这将有助于

  View rootView = findViewById(android.R.id.content).getRootView();
  rootView.setDrawingCacheEnabled(true);
  Bitmap screenshot = rootView.getDrawingCache();

让我知道,一旦你尝试。

Let me know once you try.

更新:

如果我理解正确的您的意见,您无法更改与 saveWebArchive路径(文件名)

If I have understood your comment correctly, you were not able to change path with saveWebArchive(filename).

然后,你可能想使用 saveWebArchive(字符串,布尔,ValueCallback&LT;串GT;回调)
这将节省文件给定的名字,你可以使用文件名中的回调函数做你想做到任何(如保存到外部存储或其它)。

Then you might want to use saveWebArchive(String,boolean,ValueCallback<String> callBack). This will save file with the given name and you can use that file name in the callback function to do whatever you want to (like saving to external storage or anything).

请在这里 - <一个href=\"http://developer.android.com/reference/android/webkit/WebView.html#saveWebArchive(java.lang.String,%20boolean,%20android.webkit.ValueCallback%3Cjava.lang.String%3E)\"相对=nofollow> saveWebArchive

这篇关于以视频的截图在网页视图的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆