Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用WebView在单独视图中观看视频时Android崩溃_Android_Video_Webview_Crash_Webchromeclient - Fatal编程技术网

使用WebView在单独视图中观看视频时Android崩溃

使用WebView在单独视图中观看视频时Android崩溃,android,video,webview,crash,webchromeclient,Android,Video,Webview,Crash,Webchromeclient,我有一个片段使用RelativeLayout来保存webview,并为其指定了一个自定义WebChromeClient。 当我使用webview观看Youtube视频时,它可以在单独的视图中显示视频。 但是,当我退出单独的视图并返回webview时,应用程序崩溃 /*Here is part of my WebChromeClient*/ public class CustomWebChromeClient extends WebChromeClient { /*Function fo

我有一个片段使用RelativeLayout来保存webview,并为其指定了一个自定义WebChromeClient。 当我使用webview观看Youtube视频时,它可以在单独的视图中显示视频。 但是,当我退出单独的视图并返回webview时,应用程序崩溃

/*Here is part of my WebChromeClient*/
public class CustomWebChromeClient extends WebChromeClient {

    /*Function for showing video separate from webview*/
    public void onShowCustomView(View view, CustomViewCallback callback) {
        frag.mCustomViewCallback = callback;

        //mTargetView is used as a video holder for holding the video object
        frag.mTargetView.addView(view);
        //mCustomView is the video object itself
        frag.mCustomView = view;
        //hide webview      
        frag.webview.setVisibility(View.GONE);  
        //show video holder with its video
        frag.mTargetView.setVisibility(View.VISIBLE);

        frag.mTargetView.bringToFront();

    }

    @Override
    public void onHideCustomView() {

        if (frag.mCustomView == null)
            return;

        //(I guess) use callback to hide video player widget such as play button and timebar
        frag.mCustomViewCallback.onCustomViewHidden();
        //remove video object from holder
        frag.mTargetView.removeView(frag.mCustomView);
        //hide video
        frag.mCustomView.setVisibility(View.GONE);
        frag.mCustomView = null;
        //hide video hodler
        frag.mTargetView.setVisibility(View.GONE);
        //show webview again
        frag.webview.setVisibility(View.VISIBLE);


    }

    /*... some other codes ...*/
}   
在我的主要片段活动中

/*Hide video holder when back key pressed*/
public void onBackPressed() {
    /*if is showing video, hide the view*/
    if(isShowingVideo){
        myWebChromeClient.onHideCustomView();
    }
}
详细情况:
1.在我的网络视图中
2.打开Youtube
3.转到其中一个视频页面
4.单击视频的播放图标
5.[重要信息]当它仍在加载时(在视频中保持黑色),单击它提供的全屏按钮。
6.在ShowCustomView功能上触发,然后显示全屏视频(仅隐藏网络视图和显示视频视图)
7.几秒钟的视频播放
8.按back键,并在HideCustomView上触发。(仅隐藏视频视图和显示网络视图)
9webview的视频已调整大小,大约1~2秒后,应用程序崩溃并收到一些错误消息。

错误消息:
在以下位置向ErrorReportUtils报告WebCore崩溃:

Thu Dec 11 17:37:11
Fatal signal 11 (SIGSEGV) at 0x000030de (code=0), thread 12526 (WebViewCoreThre)
[unnamed-12510-1] updateTexImage: SurfaceTexture is not attached to an OpenGL ES context
我发现了什么:
1.如果不在onHideCustomView()中使用“mCustomViewCallback.onCustomViewHidden();”,应用程序将不会崩溃,
但是由mCustomView(视频对象)创建的视频播放器小部件仍然存在。
2.在情况5中,如果我等待视频内容显示,然后单击全屏按钮,则在情况6~8后,应用程序可以正常工作。