【问题标题】:android capture youtube movie on webviewandroid 在 webview 上捕获 youtube 电影
【发布时间】:2015-04-21 09:16:11
【问题描述】:

Activity上有ImageViewscreenCapture按钮和WebView

在 WebView 上加载“http://youtube.com”。

你可以看到youtube页面并点击电影。

电影将以 html 格式播放。

点击按钮截屏。

    View root = webView.getRootView();
    root.setDrawingCacheEnabled(true);
    bmp = Bitmap.createBitmap(root.getDrawingCache());
    root.setDrawingCacheEnabled(false);
    imageView.setImageBitmap(bmp);

将捕获的图像设置为 ImageView。

但是捕获的图像上没有电影。只是黑色区域。

为什么不能拍摄电影?

如何在 WebView 上捕捉电影?

请帮帮我。

【问题讨论】:

    标签: android webview youtube capture


    【解决方案1】:

    我遇到了类似的问题。有我的场景。我使用WebView 加载网页。在HTML5写的网页中,有一个video可以播放视频。我想捕获video 的部分内容。那么,有我的代码:
    初始化WebView

    String url = ...; 
    VideoView vv;
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.setWebChromeClient(chromeClient);
    mWebView.setWebViewClient(wvClient);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setPluginsEnabled(true);
    mWebView.loadUrl(url);
    


    覆盖WebChromeClient

    @Override
    public void onShowCustomView(View view, CustomViewCallback callback) {
        super.onShowCustomView(view, callback);
        if (view instanceof FrameLayout){
            FrameLayout frame = (FrameLayout) view;
            if (frame.getFocusedChild() instanceof VideoView){
                vv = (VideoView) frame.getFocusedChild();
            }
         }
    }
    


    然后,有Capture()方法:

    public Bitmap capture(VideoView vv){
         MediaMetadataRetriever rev = new MediaMetadataRetriever();
         rev.setDataSource(mContext, Uri);//Uri is the Content URI of the data you want to play, well, call this method before the rest of the methods in this class. This method may be time-consuming.; 
         Bitmap bitmap = rev.getFrameAtTime(vv.getCurrentPosition() * 1000,
                MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
        return bitmap;
    }
    


    我不知道我的解决方案能否解决你的问题,但我希望你能从我的代码中得到启发。祝你好运。

    【讨论】:

    • @SilentKnight 我遇到了类似的问题,您的回答看起来很有希望。不过我有一个问题:uri 传递的内容是什么? Uri.parse(webView.getUrl())?
    • Uri 表示“您要播放的数据的内容 URI”。
    猜你喜欢
    • 2020-07-20
    • 1970-01-01
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    相关资源
    最近更新 更多