Authentication for Videoview in android

I am using Videoview to play http video. The Http URL requires Authentication .

So please let me know how you can configure authentication in VideoView? If there is no other alternative to view the validated video.

Thanks and respect, Sri Harsha.

+3
source share
3 answers

VideoView has a hidden method that allows you to configure HTTP headers. You can use reflection to access it. But this 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 an undocumented API, it is not guaranteed to work correctly, you must handle exceptions and have a backup plan.

+7

, : http://unixpapa.com/auth/index.html

-, auth, ( /) URL-. ( , ): http://username:password@www.yourhostname.com/whatever

http-. , OpenID OAuth. .

, , .

+1

API- setViewUri (Uri, Map) .

, MediaPlayer.setDataSource(, Uri, ):

The risk of using the reflection API is that the API may disappear in a future version ...

0
source

All Articles