在 html iframe 内的 Android webview 上播放音频时出错
Posted
技术标签:
【中文标题】在 html iframe 内的 Android webview 上播放音频时出错【英文标题】:Error playing audio on Android webview inside html iframe 【发布时间】:2014-01-28 10:30:52 【问题描述】:我无法在 android webView 中重现音频,仅适用于 android 4.4,html 代码例如:
<strong>Axel Torres</strong> ha entrevistado este sábado en ‘Marcador Internacional’ en Radio Marca a <strong>Javier Clemente</strong>, <a href=\"http://www.marcadorint.com/etiqueta/libia/\">actual seleccionador de <strong><span class='wp_keywordlink_affiliate'><a href=\"http://www.marcadorint.com/etiqueta/libia/\" title=\"Ver todas las entradas en Libia\" target=\"_blank\">Libia</a></span></strong></a>. El técnico de Barakaldo ha tratado múltiples asuntos durante la hora en la que ha estado <strong>en los micrófonos de ‘MI’</strong>, incluyendo su visión del fútbol libio, su opinión sobre los tiempos modernos en el mundo del fútbol, su experiencia en Twitter o su polémica con <strong>Juan Carlos Garrido</strong>.</p>\n<p><iframe src=\"http://www.ivoox.com/player_ek_2758812_1.html\" height=\"48\" width=\"238\" allowfullscreen=\"\" frameborder=\"0\" scrolling=\"no\"></iframe></p>\n<p>Además de la entrevista completa, en ‘MI’ recogemos algunos de los <strong>sonidos más <span class='wp_keywordlink_affiliate'><a href=\"http://www.marcadorint.com/etiqueta/destacado/\" title=\"Ver todas las entradas en destacado\" target=\"_blank\">destacado</a></span>s</strong> de la charla de Javi Clemente con Axel Torres.</p>\n<blockquote><p>“El año pasado en la liga española había un equipo que según los medios era el tercer equipo que mejor jugaba y estaba en la cola. ¿Cómo va a ser el que mejor fútbol hace si pierdes cada domingo? <strong>Es un fútbol que no es real</strong>“<strong>.</strong></p></blockquote>\n<p><iframe src=\"https://uwhisp.com/w/lkn/embed\" height=\"160\" width=\"100%\" frameborder=\"no\" scrolling=\"no\"></iframe></p>\n<blockquote><p>” La cuenta de Twitter es real. Por las tardes, que aquí hace mucho calor, no tengo nada que hacer, entro en <strong>Twitter</strong> y en algunas cosas me divierto”.</p></blockquote>\n<p><iframe src=\"https://uwhisp.com/w/lko/embed\" height=\"160\" width=\"100%\" frameborder=\"no\" scrolling=\"no\"></iframe></p>\n<blockquote><p>“Ahora ha salido lo de Twitter, que eso para mi es una bomba. Esto de Twitter es un chollo: escribir lo que yo quiero sobre lo que yo quiero. A mi me leen 11.000, si a ellos los leen un millón, ¿a mi me leen 11 millones?”</p></blockquote>\n<p><iframe src=\"https://uwhisp.com/w/lkp/embed\" height=\"160\" width=\"100%\" frameborder=\"no\" scrolling=\"no\"></iframe></p>\n<h5>Contestar a los que lo han despreciado y se han mofado de él:</h5>\n<p><iframe src=\"https://uwhisp.com/w/lkq/embed\" height=\"160\" width=\"100%\" frameborder=\"no\" scrolling=\"no\"></iframe></p>\n<blockquote><p>“Nos toman el pelo con la palabreja ‘coaching’. Es un invento, un camelo que no sirve para nada”.</p></blockquote>\n<p><iframe src=\"https://uwhisp.com/w/lkr/embed\" height=\"160\" width=\"100%\" frameborder=\"no\" scrolling=\"no\"></iframe></p>\n<blockquote><p>“No tengo ni idea [¿Hasta cuándo has firmado?]. Eso de firmar no sirve para nada. Igual no llego ni a la primera convocatoria, lo mismo te tienen tres meses que te tienen doce años. <strong>El 2017 está muy lejos</strong>, vamos a ir paso a paso”.</p></blockquote>\n<p><iframe src=\"https://uwhisp.com/w/lks/embed\" height=\"160\" width=\"100%\" frameborder=\"no\" scrolling=\"no\"></iframe></p>\n<blockquote><p>“No tiene nada que ver cómo los llamo yo [a los jugadores de Libia] y cómo se llaman ellos”.</p></blockquote>\n<p><iframe src=\"https://uwhisp.com/w/lkt/embed\" height=\"160\" width=\"100%\" frameborder=\"no\" scrolling=\"no\"></iframe></p>\n<blockquote><p>“Mañana jugamos contra ‘Buenas Noches’, que es <strong>Gabón</strong> en euskera”.</p></blockquote>\n<p><iframe src=\"https://uwhisp.com/w/lkm/embed\" height=\"160\" width=\"100%\" frameborder=\"no\" scrolling=\"no\"></iframe></p>\n<h5>Acerca de su polémica con Juan Carlos Garrido:</h5>\n<p><iframe src=\"https://uwhisp.com/w/lkl/embed\" height=\"160\" width=\"100%\" frameborder=\"no\" scrolling=\"no\"></iframe></p>\n<h5>Despedida de Javier Clemente:</h5>\n<p><iframe src=\"https://uwhisp.com/w/lkk/embed\" height=\"160\" width=\"100%\" frameborder=\"no\" scrolling=\"no\"></iframe></p>\n<h6>Foto de <span class='wp_keywordlink_affiliate'><a href=\"http://www.marcadorint.com/etiqueta/portada/\" title=\"Ver todas las entradas en portada\" target=\"_blank\">portada</a></span>: magharebia</h6>\n
<iframe src=\"http://www.ivoox.com/player_ek_2758812_1.html\"
height=\"48\" width=\"238\" allowfullscreen=\"\" frameborder=\"0\" scrolling=\"no\">
</iframe>
<iframe src=\"https://uwhisp.com/w/lkn/embed\" height=\"160\" width=\"100%\"
frameborder=\"no\" scrolling=\"no\"></iframe>
第一个带有 ivoox 链接的 iframe 可以完美运行,但所有其他带有 uwhisp 的 iframe 都无法正常工作。我可以点击播放按钮,但开始加载并且永远不会结束。
我的 WebView 设置:
contentWV.setWebChromeClient(new WebChromeClient());
contentWV.getSettings().setPluginState(PluginState.ON);
contentWV.getSettings().setjavascriptEnabled(true);
contentWV.loadDataWithBaseURL("", content, "text/html", "UTF-8", "");
我把 Manifest 放进去:
android:hardwareAccelerated="true"
日志猫在我加载网页内容时放了这个:
01-28 11:27:08.695: D/MediaPlayer(3850): Couldn't open file on client side, trying server side
01-28 11:27:09.141: I/Web Console(3850): [ 21.738s] [ima.gptproxy.GptProxy] Iframe event received on /whisp32/lkn/em with data: Name: gpt, Type: isGptPresent, Session: *, Data: "scope":"proxy", Origin: https://s0.2mdn.net
01-28 11:27:09.141: I/Web Console(3850): at https://s0.2mdn.net/instream/html5/ima3_debug.js:78
01-28 11:27:09.219: I/Web Console(3850): [ 19.797s] [ima.gptproxy.GptProxy] Iframe event received on /whisp32/lkq/em with data: Name: gpt, Type: isGptPresent, Session: *, Data: "scope":"proxy", Origin: https://s0.2mdn.net
01-28 11:27:09.219: I/Web Console(3850): at https://s0.2mdn.net/instream/html5/ima3_debug.js:78
01-28 11:27:09.227: I/Web Console(3850): [ 19.210s] [ima.gptproxy.GptProxy] Iframe event received on /whisp32/lkr/em with data: Name: gpt, Type: isGptPresent, Session: *, Data: "scope":"proxy", Origin: https://s0.2mdn.net
01-28 11:27:09.227: I/Web Console(3850): at https://s0.2mdn.net/instream/html5/ima3_debug.js:78
01-28 11:27:09.258: I/Web Console(3850): [ 18.645s] [ima.gptproxy.GptProxy] Iframe event received on /whisp32/lkk/em with data: Name: gpt, Type: isGptPresent, Session: *, Data: "scope":"proxy", Origin: https://s0.2mdn.net
01-28 11:27:09.258: I/Web Console(3850): at https://s0.2mdn.net/instream/html5/ima3_debug.js:78
01-28 11:27:09.289: E/Web Console(3850): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1 at https://s-uwhisp-com.s3.amazonaws.com/js/whisp/77804ca82c6a34ef439246a06b891bddf268a337.js:292
01-28 11:27:09.367: I/dalvikvm(3850): Jit: resizing JitTable from 4096 to 8192
01-28 11:27:09.406: I/Web Console(3850): [ 22.070s] [ima.gptproxy.GptProxy] Iframe event received on /whisp32/lkp/em with data: Name: gpt, Type: isGptPresent, Session: *, Data: "scope":"proxy", Origin: https://s0.2mdn.net
01-28 11:27:09.406: I/Web Console(3850): at https://s0.2mdn.net/instream/html5/ima3_debug.js:78
01-28 11:27:09.461: E/Web Console(3850): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1 at https://s-uwhisp-com.s3.amazonaws.com/js/whisp/77804ca82c6a34ef439246a06b891bddf268a337.js:292
01-28 11:27:09.523: I/Web Console(3850): [ 22.184s] [ima.gptproxy.GptProxy] Iframe event received on /whisp32/lko/em with data: Name: gpt, Type: isGptPresent, Session: *, Data: "scope":"proxy", Origin: https://s0.2mdn.net
01-28 11:27:09.523: I/Web Console(3850): at https://s0.2mdn.net/instream/html5/ima3_debug.js:78
01-28 11:27:09.539: E/Web Console(3850): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1 at https://s-uwhisp-com.s3.amazonaws.com/js/whisp/77804ca82c6a34ef439246a06b891bddf268a337.js:292
01-28 11:27:09.594: I/Web Console(3850): [ 18.120s] [ima.gptproxy.GptProxy] Iframe event received on /whisp32/lkm/em with data: Name: gpt, Type: isGptPresent, Session: *, Data: "scope":"proxy", Origin: https://s0.2mdn.net
01-28 11:27:09.594: I/Web Console(3850): at https://s0.2mdn.net/instream/html5/ima3_debug.js:78
01-28 11:27:09.625: I/Web Console(3850): [ 17.708s] [ima.gptproxy.GptProxy] Iframe event received on /whisp32/lkt/em with data: Name: gpt, Type: isGptPresent, Session: *, Data: "scope":"proxy", Origin: https://s0.2mdn.net
01-28 11:27:09.625: I/Web Console(3850): at https://s0.2mdn.net/instream/html5/ima3_debug.js:78
01-28 11:27:09.648: I/Web Console(3850): [ 17.536s] [ima.gptproxy.GptProxy] Iframe event received on /whisp32/lkl/em with data: Name: gpt, Type: isGptPresent, Session: *, Data: "scope":"proxy", Origin: https://s0.2mdn.net
01-28 11:27:09.648: I/Web Console(3850): at https://s0.2mdn.net/instream/html5/ima3_debug.js:78
01-28 11:27:09.680: I/Web Console(3850): [ 4.175s] [ima.gptproxy.GptProxy] Iframe event received on /whisp32/lks/em with data: Name: gpt, Type: isGptPresent, Session: *, Data: "scope":"proxy", Origin: https://s0.2mdn.net
01-28 11:27:09.680: I/Web Console(3850): at https://s0.2mdn.net/instream/html5/ima3_debug.js:78
01-28 11:27:10.031: E/Web Console(3850): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1 at https://s-uwhisp-com.s3.amazonaws.com/js/whisp/77804ca82c6a34ef439246a06b891bddf268a337.js:292
01-28 11:27:10.258: E/Web Console(3850): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1 at https://s-uwhisp-com.s3.amazonaws.com/js/whisp/77804ca82c6a34ef439246a06b891bddf268a337.js:292
01-28 11:27:10.547: E/Web Console(3850): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1 at https://s-uwhisp-com.s3.amazonaws.com/js/whisp/77804ca82c6a34ef439246a06b891bddf268a337.js:292
01-28 11:27:11.148: W/Web Console(3850): [ 16.017s] [ima.common.GptCompanionAdService] GPT companion ads service not available.
01-28 11:27:11.148: W/Web Console(3850): at https://s0.2mdn.net/instream/html5/bridge3.1.42_debug_en.html#goog_1706910922:238
01-28 11:27:12.086: W/Web Console(3850): [ 15.944s] [ima.common.GptCompanionAdService] GPT companion ads service not available.
01-28 11:27:12.086: W/Web Console(3850): at https://s0.2mdn.net/instream/html5/bridge3.1.42_debug_en.html#goog_574116096:238
01-28 11:27:12.141: W/Web Console(3850): [ 15.273s] [ima.common.GptCompanionAdService] GPT companion ads service not available.
01-28 11:27:12.141: W/Web Console(3850): at https://s0.2mdn.net/instream/html5/bridge3.1.42_debug_en.html#goog_385102197:238
01-28 11:27:12.180: W/Web Console(3850): [ 14.785s] [ima.common.GptCompanionAdService] GPT companion ads service not available.
01-28 11:27:12.180: W/Web Console(3850): at https://s0.2mdn.net/instream/html5/bridge3.1.42_debug_en.html#goog_333133509:238
01-28 11:27:12.242: W/Web Console(3850): [ 13.004s] [ima.common.GptCompanionAdService] GPT companion ads service not available.
01-28 11:27:12.242: W/Web Console(3850): at https://s0.2mdn.net/instream/html5/bridge3.1.42_debug_en.html#goog_2038632347:238
01-28 11:27:12.602: W/Web Console(3850): [ 11.629s] [ima.common.GptCompanionAdService] GPT companion ads service not available.
01-28 11:27:12.602: W/Web Console(3850): at https://s0.2mdn.net/instream/html5/bridge3.1.42_debug_en.html#goog_386198883:238
01-28 11:27:13.344: W/Web Console(3850): [ 10.654s] [ima.common.GptCompanionAdService] GPT companion ads service not available.
01-28 11:27:13.344: W/Web Console(3850): at https://s0.2mdn.net/instream/html5/bridge3.1.42_debug_en.html#goog_1680205568:238
01-28 11:27:13.531: W/Web Console(3850): [ 9.374s] [ima.common.GptCompanionAdService] GPT companion ads service not available.
01-28 11:27:13.531: W/Web Console(3850): at https://s0.2mdn.net/instream/html5/bridge3.1.42_debug_en.html#goog_806220502:238
01-28 11:27:13.617: W/Web Console(3850): [ 8.185s] [ima.common.GptCompanionAdService] GPT companion ads service not available.
01-28 11:27:13.617: W/Web Console(3850): at https://s0.2mdn.net/instream/html5/bridge3.1.42_debug_en.html#goog_158678934:238
01-28 11:27:14.172: W/Web Console(3850): [ 7.084s] [ima.common.GptCompanionAdService] GPT companion ads service not available.
01-28 11:27:14.172: W/Web Console(3850): at https://s0.2mdn.net/instream/html5/bridge3.1.42_debug_en.html#goog_545018154:238
【问题讨论】:
【参考方案1】:这可能是 URL 重定向的问题。 MediaPlayer 无法正确访问此 URL 中的此文件。
尝试将文件的原始位置放入href。
【讨论】:
您的意思是用“uwhisp.com/w/lkn”代替“uwhisp.com/w/lkn/embed\”吗? 问题在于 iframe 的实现。 Android 网络视图无法访问最终音频资源(由于重定向)“whisp-uwhisp-com.s3.amazonaws.com/9BN1LF.mp3?”。但是,另一个 iframe 使用 ajax 连接来检索音频文件“ivoox.com/listenembeded_mn_2758812_1.m4a?source=EMBEDEDHTML5”。我不知道您是否可以修改 iframe 代码,但使用第一个 iframe 实现并使用第二个 iframe 音频资源修改 src,可以正确播放音频。 我无法修改 iframe。我必须使用那个 iframe,有什么方法可以在 webview 内部或外部使用 android 来做到这一点?以上是关于在 html iframe 内的 Android webview 上播放音频时出错的主要内容,如果未能解决你的问题,请参考以下文章
layui弹窗 iframe嵌套页面内的弹窗如何覆盖到父级页面