需求
在MediaPlayer进行播放时需要设置特定的User-Agent。
首先看StackvOerflow上的讨论,总共有2篇文章。
讨论1
http://stackoverflow.com/questions/8959300/how-do-i-include-http-headers-with-mediaplayer-setdatasource
The method setDataSource(Context context, Uri uri, Map headers) has been included in the SDK (marked as @hide) for quite a long time (at least since Froyo 2.2.x, API Level 8), check out the change history:
And has been unhidden and open to public since Ice Cream Sandwich 4.0.x, API Level 14:
Workaround:
Prior to Ice Cream Sandwich 4.0.x, API Level 14, we can use reflection call this hide API:
Uri uri = Uri.parse(path);
Map headers = new HashMap();
headers.put("key1", "value1");
headers.put("key2", "value2");
mMediaPlayer = new MediaPlayer();
// Use java reflection call the hide API:
Method m