0

I recently submitted an Ionic app to the Google Play Store which was rejected due to background play with Youtube videos (when you press the power button or lock screen is applied, the video continues to play int he background. Which Play Store will not allow)

A possible fix has been found at Stop android app audio playing when device locked

But I am unsure where to apply this within the platforms/android folder.

Does anyone know which file and where to apply the code? The image below shows files that featured the onPause override, so I assume it is one of those.

Android .java files containing onPause Overrides

@Override
public void onPause() {
    super.onPause();
    myCustomWebView.onPause();
}

myCustomWebView.setWebViewClient(new WebViewClient() {
    @Override
    public void onLoadResource(WebView webview, String url) {
        super.onLoadResource(webview, url);
        if (url.contains("youtube.com")) mShouldPause = true;
    }

    //...... plus any other method you want to override

});

@Override
public void onPause() {
    super.onPause();
    // mShouldPause is just a private boolean
    if (mShouldPause) {
        myCustomWebView.onPause();
    }
    mShouldPause = false;
}
Community
  • 1
  • 1

1 Answers1

1

Can you just use Cordova's pause and resume features?

Example:

function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

// device APIs are available
//
function onDeviceReady() {
    document.addEventListener("pause", onPause, false);
    document.addEventListener("resume", onResume, false);
    document.addEventListener("menubutton", onMenuKeyDown, false);
    // Add similar listeners for other events
}

function onPause() {
    // Handle the pause event

    //Handle pausing YouTube video.
}

function onResume() {
    // Handle the resume event

    //Resume YouTube video
}

function onMenuKeyDown() {
    // Handle the menubutton event
}

https://cordova.apache.org/docs/en/latest/cordova/events/events.html

L Balsdon
  • 995
  • 8
  • 12
  • This is great, however, which file does the code go in? The OP referenced android.java file but should it not be app.component.ts or their custom youtube.ts pipe file? – me9867 May 23 '17 at 20:11