背景:
方法setDataSource(Context context,Uri uri,Map
2.2.x,API Level 8开始),请检查列出更改历史记录:
API扩展:支持在指定要播放的媒体数据的uri时可选地指定额外的请求标头的映射
自从Ice Cream Sandwich 4.0.x(API级别14)以来,它一直未被公开并向公众开放:
取消隐藏MediaPlayer的setDataSource方法,该方法将可选的HTTP标头传递给服务器
解决方法:
在API级别14的Ice Cream Sandwich 4.0.x之前,我们可以使用反射调用此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();... ...


