android - 退出页面如何关闭自动媒体?
PHP中文网
PHP中文网 2017-04-17 16:01:10
0
2
490

安卓客户端中内嵌的H5 界面,界面中有个iframe标签加载的视频,那么问题来了,如何在退出界面后自动关闭掉里面播放的视频,现在的问题是退出再重新进去,就会又开启一次媒体播放,然后就会出现两个声音。

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
阿神

WebView has a method in API 11+, onPause. You just need to call this method when Activity onPause, and the system will automatically pause the content played in all web pages. If you install it under a version lower than API 11, you can use reflection. Call this method

左手右手慢动作

I write directly like this every time, and basically I have never encountered a problem like yours. I suggest you give it a try.

    @Override
    protected void onResume() {
        if (mWebView != null) {
            mWebView.onResume();
        }
        super.onResume();
    }

    @Override
    protected void onPause() {
        if (mWebView != null) {
            mWebView.onPause();
        }
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        if (mWebView != null) {
            mWebView.destroy();
            mWebView = null;
        }
        super.onDestroy();
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template