身份验证Videoview在安卓 [英] Authentication for Videoview in android
问题描述
我使用的 Videoview 打HTTP video.That的Http视频URL需要的验证
I'm using a Videoview to play http video.That Http video url needs Authentication.
所以,请让我知道如何验证可以设置为VideoView?如果不是有没有其他的替代方案,用于查看验证视频?
So please let me know how authentication can be set to the VideoView?If not is there any other alternative for viewing authenticated video.?
感谢和放大器;问候, SREE戒。
Thanks & Regards, Sree Harsha .
推荐答案
有一个隐藏的方法VideoView,允许设置HTTP头。您可以使用反射来访问它。但是,如果服务器支持基本身份验证它只会帮助
There is a hidden method in VideoView that allows setting HTTP headers. You can use reflection to access it. But it will only help if the server supports basic authentication
Method setVideoURIMethod = videoView.getClass().getMethod("setVideoURI", Uri.class, Map.class);
Map<String, String> params = new HashMap<String, String>(1);
final String cred = login + ":" + pwd;
final String auth = "Basic " + Base64.encodeBytes(cred.getBytes("UTF-8"));
params.put("Authorization", auth);
setVideoURIMethod.invoke(videoView, uri, params);
当然,由于这是未公开的API也不能保证正常工作,你应该处理异常,并有一个后备计划。
Of course since this is undocumented API it is not guaranteed to work properly, you should handle exceptions and have a fallback plan.
这篇关于身份验证Videoview在安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!