Android WebView not stopping after user presses back

后端 未结 6 1711
傲寒
傲寒 2021-01-31 03:18

I am playing a YouTube video inside a WebView. I am able to play it, but when the person leaves the screen, I am not able to stop the audio from playing.

I tried various

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 03:38

    You can do it using the method onPause() of your Activity :

    @override
    public void onPause() {
        super.onPause();
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            webview.onPause();
        }
    }
    

    adding a validation for use in API >= 11 (Honeycomb)

提交回复
热议问题