内容简介:http://stackoverflow.com/questions/8959300/how-do-i-include-http-headers-with-mediaplayer-setdatasource
.我的目标api版本小于14,所以相信我不能使用允许头文件的新方法.如何在MediaPlayer请求中包含标题(特别是认证标头),并且仍然支持较旧的Android设备?
我的代码看起来像:
mediaPlayer.setDataSource(url); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.prepareAsync();
背景:
方法 setDataSource(Context context, Uri uri, Map<String, String> headers) 已经被包括在SDK(标记为@hide)很长一段时间(至少从Froyo 2.2.x,API 8级),请查看更改历史记录:
自从Ice Cream Sandwich 4.0.x,API Level 14:
解决方法:
在Ice Cream Sandwich 4.0.x,API Level 14之前,我们可以使用反射来调用这个hide API:
Uri uri = Uri.parse(path);
Map<String, String> headers = new HashMap<String, String>();
headers.put("key1", "value1");
headers.put("key2", "value2");
mMediaPlayer = new MediaPlayer();
// Use java reflection call the hide API:
Method method = mMediaPlayer.getClass().getMethod("setDataSource", new Class[] { Context.class, Uri.class, Map.class });
method.invoke(mMediaPlayer, new Object[] {this, uri, headers});
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.prepareAsync();
... ...
http://stackoverflow.com/questions/8959300/how-do-i-include-http-headers-with-mediaplayer-setdatasource
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- javascript – 如何使用jquery查找包含与前缀匹配的data- *属性的元素
- java – 使用JAXB编译包含相同元素的重复定义的几个XSD
- PHP 包含文件
- 包含块
- 文件包含&奇技淫巧
- 谈一谈文件包含漏洞
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Cracking the Coding Interview
Gayle Laakmann McDowell / CareerCup / 2015-7-1 / USD 39.95
Cracking the Coding Interview, 6th Edition is here to help you through this process, teaching you what you need to know and enabling you to perform at your very best. I've coached and interviewed hund......一起来看看 《Cracking the Coding Interview》 这本书的介绍吧!