Created
January 5, 2021 14:12
-
-
Save raxhaxor/e56c2fcc2d381c83983693bb02099581 to your computer and use it in GitHub Desktop.
Pause audio and video in android WebView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val audioPauseJavascipt = "function pauseAudioAndVideo(windowA){" + | |
" for(var i = 0; i < windowA.document.getElementsByTagName('video').length; i++){" + | |
" var media = windowA.document.getElementsByTagName('video')[i];" + | |
" media.pause(); " + | |
" media.currentTime = -1; " + | |
" media.volume = 0; " + | |
" }" + | |
" for(var i = 0; i < windowA.document.getElementsByTagName('audio').length; i++){" + | |
" var media = windowA.document.getElementsByTagName('audio')[i];" + | |
" media.pause(); " + | |
" media.currentTime = -1; " + | |
" media.volume = 0; " + | |
" }" + | |
" <!-- for(var i = 0; i < windowA.document.getElementsByTagName('iframe').length; i++){" + | |
" var iframeA = windowA.document.getElementsByTagName('iframe')[i];" + | |
" pauseAudioAndVideo(iframeA.contentWindow); " + | |
" } -->" + | |
"}" + | |
"pauseAudioAndVideo(this.window);"; | |
mWebView.evaluateJavascript(audioPauseJavascipt, null) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment