Buenas,
Tengo un problema con mi WebView, yo uso mi dispositivo móvil abro cualquier navegador (Chrome, Firefox), entro dentro de la web que quiero cargar en mi webview y navego sin problemas. Incluso puedo reproducir audios que están dentro de la web. Por ejemplo esta web: http://www2.radioecca.org/radio/carta/a-nuestro-aire/12038598
Pero dentro de mi aplicación, yo tengo un Fragment con un webview que me carga la página web perfectamente, pero a la hora de reproducir el audio, no hace nada.
Este es el código de mi Fragment:
@SuppressLint("SetJavaScriptEnabled")//Activa contenido javascript en el webview
public class FragmentIvooxWebView extends Fragment {
private WebView webView;
private int iContNored = 0;/*Contador de veces mostrados los mensajes de no hay red*/
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
try {
isNetworkConnected(getContext());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Método que muestra el layout con el webview
* @param inflater
* @param container
* @param savedInstanceState
* @return
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_ivoox_webview, container, false);
webView = (WebView)view.findViewById(R.id.webViewIvoox);
return view;
}
/**
* Método que valida si el dispositivo tiene conexión a internet.
* De ser afirmativo, llama al método webview para cargar la web
* @param ctx
* @return Devuelve un boolean.
* @throws Exception
*/
public boolean isNetworkConnected(Context ctx) throws Exception {
NetworkInfo ni = null;
try {
ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
ni = cm.getActiveNetworkInfo();
}catch (Exception e){
throw new Exception("Se ha producido un error al intentar validar la conección a Internet");
}
if (ni == null) {
// There are no active networks.
if(iContNored < 2){
Toast.makeText(ctx, "Aviso\n" +
"No está conectado a ninguna red, revise su conexión Wifi o Datos móviles" , Toast.LENGTH_LONG).show();
iContNored++;
}
return false;
} else{
try {
webView();
}catch (Exception e){
throw new Exception(e);
}
return true;
}
}
/**
* Método que carga la web de ivoox
*/
private void webView(){
//Cargando el Webview con par�metros espec�ficos
WebSettings webSettings = this . webView . getSettings ();
webSettings . setJavaScriptEnabled ( true );
webSettings . setDomStorageEnabled ( true );
this . webView . setWebViewClient ( new WebViewClient());
this . webView . setWebChromeClient ( new WebChromeClient());
webSettings . setLoadWithOverviewMode ( true );
webSettings . setUseWideViewPort ( true );
webView.setOnKeyListener(new View.OnKeyListener()
{
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if(event.getAction() == KeyEvent.ACTION_DOWN)
{
WebView webView = (WebView) v;
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
if(webView.canGoBack())
{
webView.goBack();
return true;
}
break;
}
}
return false;
}
});
//Carga la url en el webview
webView.loadUrl("http://www2.radioecca.org/radio/carta/a-nuestro-aire/12038598");
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
}
}
Este es el error que da:
04-07 10:14:49.278 2710-3213/ecca.radio E/EGL_emulation: eglQueryContext 32c0 EGL_BAD_ATTRIBUTE
04-07 10:14:49.278 2710-3213/ecca.radio E/EGL_emulation: tid 3213: eglQueryContext(1484): error 0x3004 (EGL_BAD_ATTRIBUTE)
04-07 10:14:49.615 2710-2710/ecca.radio I/chromium: [INFO:CONSOLE(0)] "Mixed Content: The page at 'https://www.ivoox.com/player_ej_12038598_4_1.html?c1=0069ad' was loaded over HTTPS, but requested an insecure video 'http://files.ivoox.com/listen/12038598'. This request has been blocked; the content must be served over HTTPS.", source: https://www.ivoox.com/player_ej_12038598_4_1.html?c1=0069ad (0)
Curiosamente yo antes cargaba otra página en el webview y si me dejaba escuchar los audios: http://m.ivoox.com/escuchar-radio-ecca_nq_646_1.html
EDICIÓN 1:
El problema lo estoy teniendo dentro de un iframe. Si yo uso el iframe a continuación, no funciona.
<iframe id="audio_12038598" frameborder="0" allowfullscreen="" scrolling="no" height="200" style="border:1px solid #EEE; box-sizing:border-box; width:100%;" src="https://www.ivoox.com/player_ej_12038598_4_1.html?c1=0069ad"></iframe>
Pero si uso el siguiente iframe, si funciona.
<iframe id="audio_12038598" frameborder="0" allowfullscreen="" scrolling="no" height="200" style="border:1px solid #EEE; box-sizing:border-box; width:100%;" src="http://www.ivoox.com/player_ej_12038598_4_1.html?c1=0069ad"></iframe>
Lo único que cambia de un iframe a otro es el https por http.
Este iframe es autogenerado por la plataforma ivoox, y no tengo manera de tocarlo.
¿Hay alguna manera de que el webview acepte iframes con https
?
Muchas gracias por vuestra ayuda. Estoy aprendiendo mucho de esta comunidad.