JWPlayer API Javascript para Android Webview

Estoy tratando de obtener JWPlayer para devolver una alerta cuando se producen algunos eventos específicos de un reproductor flash que reproduce un video local. Si observa el código siguiente, onComplete, JWPlayer debe devolver una alerta, que puede ser interceptada por onJsAlert desde setWebChromeClient para poder hacer cosas con esa información. ¿Estoy haciendo algo mal?

Una posible razón, puedo encontrar aquí: JWplayer Javascript interacción no funciona que se está cargando localmente. ¿Hay alguna forma de evitar este problema? ¿Sería más fácil cargar de alguna manera llamando a localhost? ¿Eso es posible?

Para aquellos que estén interesados ​​en saber por qué genera un archivo HTML en lugar de simplemente tener un movimiento de los activos, después de explorar Internet para averiguar cómo conseguir que un reproductor flv local funcione correctamente, la mejor opción era generar el archivo HTML con el archivo HTML. Información personalizada y escribir el archivo en el mismo directorio que el FLV (de ahí la función FileWriter).

Código HTML para JWPlayer embed:

private void createVideoHtml(File flvDirectory, File htmlFile, String videofilename) { String htmlPre = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"></head><body style='margin:0; padding:0;'>"; String htmlCode = "<script type='text/javascript' src='"+ flvDirectory.getAbsolutePath() + "/jwplayer.js'></script>" + "<div id='mediaspace'>EZ Stream TV FLV Player</div>" + "<script type='text/javascript'>" + "jwplayer('mediaspace').setup({" + "'flashplayer': '"+ flvDirectory.getAbsolutePath() + "/player.swf', 'file': '" + videofilename + "', 'backcolor': 'FFFFFF', 'frontcolor': '000000', 'lightcolor': '000000'," + "'screencolor': '000000', 'volume': '100', 'autostart': 'true', 'mute': 'false', 'quality': 'false', 'controlbar': 'bottom', 'width': '100%', 'height': '100%'," + "events: { " + "onComplete: function() { alert('COMPLETED');}" + "}});" + "</script>"; String htmlPost = "</body></html>"; String finalHTML = htmlPre + htmlCode + htmlPost; try { FileWriter f = new FileWriter(htmlFile); PrintWriter p = new PrintWriter(f); p.print(finalHTML); p.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 

Código para la visualización web y el manejo de la alerta Javscript:

 webView = (WebView)findViewById(R.id.web_player); webView.getSettings().setBuiltInZoomControls(false); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setLoadsImagesAutomatically(true); webView.getSettings().setPluginsEnabled(true); webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); webView.getSettings().setAllowFileAccess(true); webView.setInitialScale(60); webView.setBackgroundColor(Color.BLACK); getWindow().addFlags(128); webView.getSettings().setUserAgentString("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)"); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result) { Log.d(TAG, message); new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show(); result.confirm(); return true; } }); 

Puede consultar el código siguiente para JWPlayer a Webview

 private void createVideoHtml(File flvDirectory, File htmlFile, String videofilename) { String htmlPre = "<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"></head><body style='margin:0; padding:0;'>"; String htmlCode = "<script type='text/javascript' src='"+ flvDirectory.getAbsolutePath() + "/jwplayer.js'></script>" + "<div id='mediaspace'>EZ Stream TV FLV Player</div>" + "<script type='text/javascript'>" + "jwplayer('mediaspace').setup({" + "'flashplayer': '"+ flvDirectory.getAbsolutePath() + "/player.swf', 'file': '" + videofilename + "', 'backcolor': 'FFFFFF', 'frontcolor': '000000', 'lightcolor': '000000'," + "'screencolor': '000000', 'volume': '100', 'autostart': 'true', 'mute': 'false', 'quality': 'false', 'controlbar': 'bottom', 'width': '100%', 'height': '100%'," + "events: { " + "onComplete: function() { alert('COMPLETED');}" + "}});" + "</script>"; String htmlPost = "</body></html>"; String finalHTML = htmlPre + htmlCode + htmlPost; try { FileWriter f = new FileWriter(htmlFile); PrintWriter p = new PrintWriter(f); p.print(finalHTML); p.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } webView = (WebView)findViewById(R.id.web_player); webView.getSettings().setBuiltInZoomControls(false); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setLoadsImagesAutomatically(true); webView.getSettings().setPluginsEnabled(true); webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); webView.getSettings().setAllowFileAccess(true); webView.setInitialScale(60); webView.setBackgroundColor(Color.BLACK); getWindow().addFlags(128); webView.getSettings().setUserAgentString("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)"); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result) { Log.d(TAG, message); new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show(); result.confirm(); return true; } }); 

Tuve el mismo problema mientras trabajaba con jwplayer, mi conclusión fue que el evento onComplete no es confiable en algunos casos. ¿Puede hacer referencia a otros eventos que funcionan como el evento onTime?

De lo contrario, utilice el evento onIdle y mida el tiempo restante (getDuration – getPosition) para obtener un evento onComplete personalizado.

  • Lento touchmove de sondeo en Android vía navegador vs aplicación nativa
  • JQuery - Permitir teclado Autoshow en móvil
  • ¿Cómo puedo dirigirme al navegador Samsung Android?
  • Obtenga coordenadas de Hardware GPS
  • Weinre no puede abrir archivos .js
  • ¿El enlace JavaScript de JNI de Android pasa eficientemente TypedArray / ArrayBuffer a Java como una matriz?
  • El error de referencia onnotification no está definido en la notificación de push cordova android
  • Menú contextual y dispositivos con pantalla táctil
  • ERR_ADDRESS_UNREACHABLE para abrir mi localhost en Chrome Android
  • HTML localStorage es nulo en Android cuando se usa webview
  • ¿Cómo resaltar el texto permanentemente en la vista web de Android?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.