Reputation: 443
I have created one android activity and in that i have a web view. I have given a html5 file path to webview.
Html 5 file contains a Video Tag in which I am calling android compatible mp4 video from server like: "http://xxx/test/abc.mp4".
Video plays nicely in webview but when video is in buffering mode and i close the webview or close the activity by pressing back button on android tablet, then after that video still plays in backgroud even if activty is finished.
When i close the activity and video is in play mode(not in buffering mode) then video stops properly without any problem.
I have tried to close the webview thread as mentioned in:"http://stackoverflow.com/questions/5946698/how-to-stop-youtube-video-playing-in-android-webview" but no luck....
Please please help on this. I am stuck in the issue from last 5 days.
Thanks in advance... Ketan
Upvotes: 2
Views: 2460
Reputation: 1760
Raneez Ahmed's answer is correct. However, if you are developing for API level 11 or above, you can access WebView.onPause directly without reflection:
@Override
public void onPause() {
webview.onPause();
super.onPause();
}
Remember to also implement onResume:
@Override
public void onResume() {
super.onResume();
webview.onResume();
}
Upvotes: 2
Reputation: 3828
The only way is to call WebView's onPause method from your own Activity's onPause method
@Override
public void onPause() {
super.onPause();
try {
Class.forName("android.webkit.WebView")
.getMethod("onPause", (Class[]) null)
.invoke(webview, (Object[]) null);
} catch(ClassNotFoundException cnfe) {
...
} catch(NoSuchMethodException nsme) {
...
} catch(InvocationTargetException ite) {
...
} catch (IllegalAccessException iae) {
...
}
}
Upvotes: 1