I'm using a Videoview to play http video.That Http video url needs Authentication.
So please let me know how authentication can be set to the VideoView?If not is there any other alternative for viewing authenticated video.?
Thanks & Regards, Sree Harsha .
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);
Of course since this is undocumented API it is not guaranteed to work properly, you should handle exceptions and have a fallback plan.
First you should know what kind of authentication is required by this server: http://unixpapa.com/auth/index.html
Second, depending of auth type, you should provide auth parameters (username/password) inside the URL. Usually this will be accepted (but not necessatilly, you should test): http://username:[email protected]/whatever
This are basic, http-style authentications. Modern sites use other options such as OpenID and OAuth. This are a bit harder to implement.
Anyhow, you should know type type of authentication, before you start looking for solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With