我正在尝试从具有基本身份验证的 SharePoint 服务器 URL 流式传输和播放视频(用户名密码)在我的 Android 设备中browser / Media Player /VideoView
但我得到了
错误
sorry this video can’t be played.
URL 内的身份验证参数(用户名/密码)也不起作用(例如:http://用户名:[电子邮件受保护]/测试.mp4 http://username:password@www.hostname.com/test.mp4 )
但我可以使用带有身份验证的 Android HTTP 下载类来下载并播放它。
任何人都可以建议如何为流视频的 VideoView 类设置身份验证
提前致谢 !!
如果有人仍在寻找答案这是一种在视频视图中设置身份验证的方法。
Map<String, String> header= new HashMap<String, String>(1);
final String cred = "your_username" + ":" + "your_password";
final String auth = "Basic "+ Base64.encodeToString(cred.getBytes(),Base64.URL_SAFE|Base64.NO_WRAP);
header.put("Authorization", auth);
videoView.setVideoURI(Uri.parse("your url"),header);
videoView.start();
但对于较低的 api,setVdeoUri 方法是隐藏的。你可以看到这个答案 https://stackoverflow.com/a/16787575/2579281
如果你正在使用谷歌Exo播放器 https://github.com/google/ExoPlayer您必须像这样设置数据源。
final String cred = "username" + ":" + "password";
final String auth = "Basic "+ Base64.encodeToString(cred.getBytes(),Base64.URL_SAFE|Base64.NO_WRAP);
DefaultHttpDataSource dataSource = new DefaultHttpDataSource(userAgent, null);
dataSource.setRequestProperty("Authorization", auth);
dataSource.setRequestProperty("Accept", "...");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)