当用户单击视频控制栏中的全屏按钮时,我试图获取 HTML5 视频 URI。根据this http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/webkit/HTML5VideoFullScreen.java,Android 4.0中的HTML5视频视图是SurfaceView,而不是VideoView。
有人能告诉我如何获取 SurfaceVideoView 中的 URI 吗?这是我的代码。多谢。
webView.setWebChromeClient(new WebChromeClient(){
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
super.onShowCustomView(view, callback);
if (view instanceof FrameLayout){
final FrameLayout frame = (FrameLayout) view;
if (frame.getFocusedChild() instanceof SurfaceView){
SurfaceView video= (SurfaceView) frame.getFocusedChild();
}
}
});
简单,使用反射。把这个放在里面onShowCustomView()
method:
android.net.Uri mUri = null;
try
{
@SuppressWarnings("rawtypes")
Class _VideoSurfaceView_Class_ = Class.forName("android.webkit.HTML5VideoFullScreen$VideoSurfaceView");
java.lang.reflect.Field _HTML5VideoFullScreen_Field_ = _VideoSurfaceView_Class_.getDeclaredField("this$0");
_HTML5VideoFullScreen_Field_.setAccessible(true);
Object _HTML5VideoFullScreen_Instance_ = _HTML5VideoFullScreen_Field_.get(((FrameLayout) view).getFocusedChild());
@SuppressWarnings("rawtypes")
Class _HTML5VideoView_Class_ = _HTML5VideoFullScreen_Field_.getType().getSuperclass();
java.lang.reflect.Field _mUri_Field_ = _HTML5VideoView_Class_.getDeclaredField("mUri");
_mUri_Field_.setAccessible(true);
mUri = (Uri) _mUri_Field_.get(_HTML5VideoFullScreen_Instance_);
}
catch (Exception ex)
{
}
if (mUri != null)
{
// There you have, mUri is the URI of the video
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)