Skip to content

Instantly share code, notes, and snippets.

@raxhaxor
Created January 5, 2021 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raxhaxor/e56c2fcc2d381c83983693bb02099581 to your computer and use it in GitHub Desktop.
Save raxhaxor/e56c2fcc2d381c83983693bb02099581 to your computer and use it in GitHub Desktop.
Pause audio and video in android WebView
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