9

I'm currently working on an application with screen orientation portrait, and i have html 5 video that need fullscreen support. I added to the webview a WebChromeClient, overrided few methods. Everything is working fine when i stick to the portrait orientation, but when i try to switch orientation to landscape when going fullscreen, i got a crash. Any clue ?

Overrided methods:

public void onShowCustomView(View view, CustomViewCallback callback) {
    super.onShowCustomView(view, callback);
    if (mCustomViewContainer != null) {
        callback.onCustomViewHidden();
        return;
    }
    if(interfazWeb==null)
        interfazWeb = (FragTabActivity) getActivity();
        if (view instanceof FrameLayout) {
            mCustomViewContainer = (FrameLayout) view;
            mCustomViewCallback = callback;
            interfazWeb.getCustomContentView().setVisibility(View.INVISIBLE);
            interfazWeb.addContentView(mCustomViewContainer, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, Gravity.CENTER));
            interfazWeb.setBackDelegate(new BackDelegate(){

                public boolean shouldOverrideBackButton() {
                    if(mCustomViewCallback!=null){//first calling onHideCustomView()
                        onHideCustomView();
                        return true;
                    }
                    return false;
                }

            });
            mCustomViewContainer.bringToFront();
            //interfazWeb.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    }

    @Override
    public void onHideCustomView() {
        // TODO Auto-generated method stub
            if(interfazWeb==null)
                interfazWeb = (FragTabActivity) getActivity();
            if(mCustomViewContainer!=null){
                ViewGroup parent = (ViewGroup) interfazWeb.getCustomContentView().getParent();
                if(parent!=null){
                    parent.removeView(mCustomViewContainer);
                    interfazWeb.getCustomContentView().setVisibility(View.VISIBLE);
                }
            }
            if(mCustomViewCallback!=null){
                mCustomViewCallback.onCustomViewHidden();
                mCustomViewCallback = null;
            }
            //interfazWeb.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }

        @Override
        public Bitmap getDefaultVideoPoster() {
            // TODO Auto-generated method stub
            return Bitmap.createBitmap(1, 1, Config.ARGB_8888);
        }

        @Override
        public View getVideoLoadingProgressView() {
            // TODO Auto-generated method stub
            return new ProgressBar((Context) getActivity());
        }

Log says:

10-31 11:09:36.336: E/AndroidRuntime(8098): java.lang.NullPointerException
10-31 11:09:36.336: E/AndroidRuntime(8098):     at android.webkit.HTML5VideoView.isPlaying(HTML5VideoView.java:122)
10-31 11:09:36.336: E/AndroidRuntime(8098):     at android.webkit.HTML5VideoViewProxy$VideoPlayer.isPlaying(HTML5VideoViewProxy.java:253)
10-31 11:09:36.336: E/AndroidRuntime(8098):     at android.webkit.HTML5VideoViewProxy.handleMessage(HTML5VideoViewProxy.java:402)
10-31 11:09:36.336: E/AndroidRuntime(8098):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-31 11:09:36.336: E/AndroidRuntime(8098):     at android.os.Looper.loop(Looper.java:137)
10-31 11:09:36.336: E/AndroidRuntime(8098):     at android.app.ActivityThread.main(ActivityThread.java:4758)
10-31 11:09:36.336: E/AndroidRuntime(8098):     at java.lang.reflect.Method.invokeNative(Native Method)
10-31 11:09:36.336: E/AndroidRuntime(8098):     at java.lang.reflect.Method.invoke(Method.java:511)
10-31 11:09:36.336: E/AndroidRuntime(8098):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-31 11:09:36.336: E/AndroidRuntime(8098):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-31 11:09:36.336: E/AndroidRuntime(8098):     at dalvik.system.NativeStart.main(Native Method)

EDIT: I have this line in my manifest:

android:configChanges="keyboardHidden|orientation|locale|screenLayout"
parser_failed
  • 697
  • 9
  • 20
  • could you help me to solve this [Issue](http://stackoverflow.com/questions/14156411/loading-youtube-video-through-i-frame-in-android-webview) – edwin Jan 08 '13 at 05:25
  • 2
    I have exactly the same problem, but only on galaxy S3, when you press back (for exit fullscreen) – Pauland Jan 14 '13 at 14:40
  • @Pauland Did you get the solution for this problem? I am also getting this issue in S3. Can you please help me? – Noundla Sandeep Mar 11 '13 at 08:37
  • @noundla yes my old code (solved) http://pastebin.com/2PFZd2XV If i remember, the prb is resolved with onBackPressed function – Pauland Mar 12 '13 at 17:56
  • I think I solved it here: http://stackoverflow.com/questions/34718725/white-screen-after-closing-fullscreen-video-opened-from-webview – Jacek Kwiecień Jan 11 '16 at 16:02

2 Answers2

0

When you switch the orientation the application resets it self starting with oncreate event. It doesn t just simple change the height and width and related stuff. That why you are getting a null exception one of the control you have created is not exist this time. Probably HTML5View.

What you should do is keep track of the video position and in case of switch reload all the controls according starting with the last position.

Onur Topal
  • 3,042
  • 1
  • 24
  • 41
  • I'm currently handling orientation changes programmatically, at Activity level. So it's not supposed to be destroyed and recreated – parser_failed Oct 31 '12 at 12:20
  • As you said Onur, everything is destroyed during orientation change, despite me retaining the state and handling config changes. I guess i'll have to dive in another app source code to find how they handled this part. I just hope to find a simpler example than the default web browser. – parser_failed Jan 15 '13 at 14:28
  • How could I reload all the controls back. can you eleborate? – Pravinsingh Waghela Sep 05 '14 at 10:41
0

You can try handling the orientation changes from the Manifest by adding this to your Activity:

android:configChanges="orientation|screenLayout"

I used to have the same problem but this worked for me.

Gonan
  • 588
  • 7
  • 18
  • Well, you mention - not in the original question - that you are handling orientation changes programmatically which shouldn't work in any case unless you're setting the attributes I mentioned in the Manifest. So maybe you can try this approach. – Gonan Feb 07 '13 at 09:45