paradox37
paradox37

Reputation: 435

Phonegap html5 video full screen breaks back button behavior

I'm using Phonegap in combination with Framework7.

I have a really strange issue. I'm using html5 video tag to stream video. Streaming works perfectly fine.

Issue appears when I go fullscreen. After exiting full screen and pressing back button applications closes instead of going on previous screen.

If I play video and don't go fullscreen it will work normally and go back to previous screen.

This is the code that I have: document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    document.addEventListener("backbutton", function (e) {
        alert('backbutton');
        if (mainView.activePage.name=='index'){
            navigator.notification.confirm("Are you sure want to exit from App?", onConfirmExit, "Confirmation", "Yes,No");
            function onConfirmExit(button) {
                if(button==2){ //If User select a No, then return back;
                    return;
                }else{
                    navigator.app.exitApp(); // If user select a Yes, quit from the app.
                }
            }
        }
        else{
            mainView.router.back();
        }
    }, false);
}

The alert in the code will not appear if I go fullscreen, exit from fullscreen and press back.

Is this some bug or I'm doing something wrong?

Upvotes: 1

Views: 1067

Answers (1)

Rohit
Rohit

Reputation: 111

I had a similar problem in an Ionic2 app which uses a custom video player plugin. When I switch the player to full screen and back, Ionic's hardware back button functionality stops working: the app closes immediately on clicking the hardware back button instead of popping the next view from Ionic's navigation stack.

I fixed my problem using the solution suggested here: https://github.com/floatinghotpot/cordova-admob-pro/issues/148

I had to override dispatchKeyEvent() in CordovaActivity.java:

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (this.appView != null) {
        View webview = this.appView.getView();
        if (webview != null) {            
            return webview.dispatchKeyEvent(event);
        }
        return true;
    }
    return false;
}

This is a hack, of course, since a core Cordova file has been modified, but I have yet to find a better solution.

Upvotes: 0

Related Questions