HTML5 video opened in the background does not stop. I open webview in fragment. I tried the following code:
public void onPause(){ mWebView.onPause(); try { Class.forName("android.webkit.WebView") .getMethod("onPause", (Class[]) null) .invoke(mWebView, (Object[]) null); } catch(ClassNotFoundException e) { e.printStackTrace(); } catch(NoSuchMethodException e) { e.printStackTrace(); } catch(InvocationTargetException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } super.onPause(); }
this code stops the sound, but the media player is still running in the background. When I open the same fragment again, the application will crash:
V/MediaPlayer(1173): notify(100, -38, 0) callback on disconnected mediaplayer W/dalvikvm(1173): threadid=1: thread exiting with uncaught exception (group=0x41212438) E/AndroidRuntime(1173): FATAL EXCEPTION: main E/AndroidRuntime(1173): android.view.WindowManager$BadTokenException: Unable to add window
source share