Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my full screen webview constantly closing immediately after opening?

My fullscreen video webview almost always closes immediately after opening, sometimes it works. You can see the screen flashing to full screen and back to original almost everytime i click the fullscreen button on a youtube video. What could be the reason for this?

The webview is displayed in a tablayout/viewpager setup with some other fragments.

I have used this code to display the video: https://github.com/cprcrack/VideoEnabledWebView

And now I am using this one https://github.com/GoogleChrome/chromium-webview-samples/blob/master/fullscreen-video-sample/app/src/main/java/fullscreenvideosample/android/chrome/google/com/fullscreenvideosample/MainActivity.java

They produce exactly the same behavior.

Logs when full screen fails and goes back to normal right after opening:

07-14 17:41:06.694 D/ViewRootImpl@33432e1[GroupActivity]: ViewPostImeInputStage processPointer 0
07-14 17:41:06.786 D/ViewRootImpl@33432e1[GroupActivity]: ViewPostImeInputStage processPointer 1
07-14 17:41:06.803 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392
07-14 17:41:07.512 D/ViewRootImpl@33432e1[GroupActivity]: ViewPostImeInputStage processPointer 0
07-14 17:41:07.592 D/ViewRootImpl@33432e1[GroupActivity]: ViewPostImeInputStage processPointer 1
07-14 17:41:07.615 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392
07-14 17:41:07.709 V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@3e22579 nm : com.linkhubapp ic=null
07-14 17:41:07.709 I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus
07-14 17:41:07.713 D/InputTransport: Input channel constructed: fd=152
07-14 17:41:07.714 D/InputTransport: Input channel destroyed: fd=159
07-14 17:41:07.714 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392
07-14 17:41:07.751 D/ViewRootImpl@33432e1[GroupActivity]: Relayout returned: oldFrame=[0,0][1440,2560] newFrame=[0,0][1440,2560] result=0x1 surface={isValid=true -1176543232} surfaceGenerationChanged=false
07-14 17:41:07.911 D/ViewRootImpl@33432e1[GroupActivity]: Relayout returned: oldFrame=[0,0][1440,2560] newFrame=[0,0][1440,2560] result=0x7 surface={isValid=true -1273339904} surfaceGenerationChanged=true
07-14 17:41:07.921 D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000,  [1440x2560]-format:1
07-14 17:41:07.922 D/ViewRootImpl@33432e1[GroupActivity]: mHardwareRenderer.updateSurface() mSurface={isValid=true -1273339904}
07-14 17:41:07.974 D/SurfaceView: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,875][1440,1685] result=0x7 surface={Surface(name=null)/@0xb9ffb70 isValid=true -1178691584}
07-14 17:41:08.047 D/SurfaceView: Relayout returned: oldFrame=[0,875][1440,1685] newFrame=[0,875][1440,1685] result=0x5 surface={Surface(name=null)/@0xb9ffb70 isValid=false 0}
07-14 17:41:08.095 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392
07-14 17:41:08.163 D/ViewRootImpl@33432e1[GroupActivity]: Relayout returned: oldFrame=[0,0][1440,2560] newFrame=[0,0][1440,2560] result=0x1 surface={isValid=true -1273339904} surfaceGenerationChanged=false
07-14 17:41:08.232 V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@1772e0f nm : com.linkhubapp ic=null
07-14 17:41:08.232 I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus
07-14 17:41:08.233 D/InputTransport: Input channel constructed: fd=173
07-14 17:41:08.233 D/InputTransport: Input channel destroyed: fd=152

Logs when full screen succeeds:

07-14 17:41:27.987 D/ViewRootImpl@33432e1[GroupActivity]: ViewPostImeInputStage processPointer 0
07-14 17:41:28.023 D/ViewRootImpl@33432e1[GroupActivity]: ViewPostImeInputStage processPointer 1
07-14 17:41:28.048 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392
07-14 17:41:28.496 D/ViewRootImpl@33432e1[GroupActivity]: ViewPostImeInputStage processPointer 0
07-14 17:41:28.571 D/ViewRootImpl@33432e1[GroupActivity]: ViewPostImeInputStage processPointer 1
07-14 17:41:28.616 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392
07-14 17:41:28.719 V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@80b2646 nm : com.linkhubapp ic=null
07-14 17:41:28.719 I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus
07-14 17:41:28.725 D/InputTransport: Input channel constructed: fd=155
07-14 17:41:28.725 D/InputTransport: Input channel destroyed: fd=173
07-14 17:41:28.725 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392
07-14 17:41:28.766 D/ViewRootImpl@33432e1[GroupActivity]: Relayout returned: oldFrame=[0,0][1440,2560] newFrame=[0,0][1440,2560] result=0x1 surface={isValid=true -1273339904} surfaceGenerationChanged=false
07-14 17:41:28.956 D/ViewRootImpl@33432e1[GroupActivity]: Relayout returned: oldFrame=[0,0][1440,2560] newFrame=[0,0][1440,2560] result=0x1 surface={isValid=true -1273339904} surfaceGenerationChanged=false
07-14 17:41:29.036 D/SurfaceView: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,875][1440,1685] result=0x7 surface={Surface(name=null)/@0xc360d2 isValid=true -1273337856}
07-14 17:41:29.089 D/SurfaceView: Relayout returned: oldFrame=[0,875][1440,1685] newFrame=[0,875][1440,1685] result=0x1 surface={Surface(name=null)/@0xc360d2 isValid=true -1311279104}

EDIT: It seems to be happening only on youtube. Tested Vimeo vs youtube. Vimeo opens everytime.

like image 965
CantThinkOfAnything Avatar asked Jul 14 '17 15:07

CantThinkOfAnything


2 Answers

The best thing I can think of, is that your device is out of ram. So I have some suggestions for you.

  • First of all, test it on your device when all of its ram is free and check the result.

  • Second, you have mentioned that you have a Galaxy S6 and a Galaxy S3, run your app on both devices.

  • Also it is very very helpful if you can test your app on another Galaxy S6 and see if it repeats.

After gathering these information, you may be able to find a solution for your problem.

Another thing that you can test, is use android:hardwareAccelerated="true" and check if it helps.

like image 119
A. Badakhshan Avatar answered Nov 14 '22 23:11

A. Badakhshan


This not answers your question directly, but offers an alternative.

Depending on your use case, it may be acceptable to display the video on the YouTube App instead of inside WebView. Most Android devices (if not all) have the YouTube app installed.

public void playVideo(String key){

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + key));

    // Check if the youtube app exists on the device
    if (intent.resolveActivity(getPackageManager()) == null) {
        // If the youtube app doesn't exist, then use the browser
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://www.youtube.com/watch?v=" + key));
    } else {
        startActivity(intent);
    }
}

It will require the user to hit "Back" to return to your app later. But it will probably give a better video experience to the user.

like image 42
Amir Uval Avatar answered Nov 15 '22 00:11

Amir Uval