Android:Html 5视频不会停止活动完成 [英] Android:Html 5 Video does not stop on activity finish
问题描述
我创建了一个Android活动,并且我有一个Web视图。我给了webview的html5文件路径。
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文件包含一个视频标签,我在服务器中调用android兼容的mp4视频,如:http:// xxx / test / abc.mp4。
Html 5 file contains a Video Tag in which I am calling android compatible mp4 video from server like: "http://xxx/test/abc.mp4".
视频在webview中播放得很好,但是当视频处于缓冲模式并关闭webview或通过按下后退按钮关闭活动时Android平板电脑,然后该视频仍然在背景中播放,即使激活完成。
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.
我试图关闭webview线程,如下所述:http://stackoverflow.com/questions/5946698/how-to -stop-youtube-video-in-android-webview但没有运气....
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....
请帮助解决这个问题。我在最近5天遇到了问题。
Please please help on this. I am stuck in the issue from last 5 days.
提前致谢...
Ketan
Thanks in advance... Ketan
推荐答案
Raneez Ahmed的回答是正确的。但是,如果您正在为API级别11或更高级别开发,则可以直接访问WebView.onPause而无需反射:
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();
}
还记得实现onResume:
Remember to also implement onResume:
@Override
public void onResume() {
super.onResume();
webview.onResume();
}
这篇关于Android:Html 5视频不会停止活动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!