屏幕锁定时,WebView媒体内容停止(调用活动的onStop) [英] WebView media content stops when the screen is locked ( activity's onStop is called)

查看:138
本文介绍了屏幕锁定时,WebView媒体内容停止(调用活动的onStop)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,可以在MainActivity的WebView中播放视频.我遇到的问题是,每当锁定屏幕时,视频就会暂停(调用onStop活动,即WebView中的视频暂停时).

I have an App that plays a video inside a WebView on my MainActivity. The problem I am having is that the video is pausing whenever I lock the screen (Activity's onStop is called, that is when the video in the WebView is paused).

但是这种行为仅发生在 Apis> = Lollipop(5.0)上.

But this behavior only occurs on Apis >= Lollipop(5.0).

我到处都在寻找解决方案,但找不到任何东西.我只希望即使用户在LockScreen上也能继续播放视频.

I searched everywhere for a solution, but I could not find anything. I just want the video to keep playing even when the user is on LockScreen.

推荐答案

如果您的WebView由于onStop而暂停,则可以覆盖WebView中的onWindowVisibilityChanged:

If your WebView is pausing because of the onStop, you can override onWindowVisibilityChanged from WebView:

public class MyWebView extends WebView {

    public MyWebView(Context context) {
        super(context);
    }

    public MyWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onWindowVisibilityChanged(int visibility) {
        if (visibility != View.GONE) super.onWindowVisibilityChanged(visibility);
    }
}

这篇关于屏幕锁定时,WebView媒体内容停止(调用活动的onStop)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆