Android WebView加载H5音视频自动播放、关闭Activity停止播放

在Android加载H5,实现H5中的音视频自动播放 
在Activity中添加代码:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            mWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);
        }

关闭Activity后停止音视频播放:

@Override
    protected void onPause() {
        super.onPause();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mWebView.onPause();
        }
    }
    @Override
    protected void onResume() {
        super.onResume();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mWebView.onResume();
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mWebView.resumeTimers();
        mWebView.destroy();
    }

猜你喜欢

转载自blog.csdn.net/connor__ak/article/details/81086085