Webview does not load specific audios within the web

2

Good morning,

I have a problem with my WebView, I use my mobile device I open any browser (Chrome, Firefox), I enter into the web that I want to load in my webview and I navigate without problems. I can even play audios that are inside the web. For example, this website: link

But within my application, I have a Fragment with a webview that loads the web page perfectly, but when it comes to playing the audio, it does not do anything.

This is the code of my 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);
        }
    });

}

}

This is the error it gives:

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)

Interestingly I used to load another page in the webview and if you let me listen to the audios: link

EDITION 1:

The problem I'm having is within an iframe. If I use the iframe then it does not work.

<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>

But if I use the following iframe, if it works.

<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>

The only thing that changes from one iframe to another is the https for http.

This iframe is self-generated by the ivoox platform, and I have no way to touch it. Is there any way that webview acepte iframes con https ?

Thank you very much for your help. I'm learning a lot from this community.

    
asked by Natlum 07.04.2017 в 12:50
source

2 answers

-1

Solved.

I have changed the way in which the iframes are generated, now requires to always put the url with http from the web page.

Greetings and thank you very much for your help.

    
answered by 18.04.2017 / 11:29
source
1

If you try this in the device browser it can work without a doubt but if you load the page in WebView it may not work correctly:

This is a question in which you want to perform in a WebView the same thing that you do in a browser: "The main reason is that in Android, unlike iOS, for example, WebView has a limited browser."

How to locate multiple destinations on a map?

and this is another similar:

How to upload files from webview with php and javascript

The option in this case is to use a interface , and the method that is sent call in the application play the audio.

    
answered by 07.04.2017 в 17:54