2012-10-28 31 views
6

这个问题以前已经问过,但现在使用新版本的Android(直到果冻豆),我想知道是否有任何进展,下载和流式传输文件在同一时间。从API,它看起来并不像它的固有的可能,因为这些都是可用的setDataSource方法:Android MediaPlayer - 重新同时下载和流式传输

void setDataSource(String path) 
Sets the data source (file-path or http/rtsp URL) to use. 
void setDataSource(Context context, Uri uri, Map<String, String> headers) 
Sets the data source as a content Uri. 
void setDataSource(Context context, Uri uri) 
Sets the data source as a content Uri. 
void setDataSource(FileDescriptor fd, long offset, long length) 
Sets the data source (FileDescriptor) to use. 
void setDataSource(FileDescriptor fd) 
Sets the data source (FileDescriptor) to use. 

遗憾的是它不接受任何形式的一个InputStream。有些示例使用旧的NPR代理代码在Android应用程序中打开本地Web服务器,远程下载内容,并将请求的数据输出到任何侦听套接字,但该代码已超过2年,仍然用作标准为完成这项任务(即使很多人报告有口吃问题等)。

我已经研究过MediaPlayer类,并希望将其扩展为允许此行为,但是很多实现都是通过本机代码完成的,从我读过的内容来看,不同的设备制造商实现本地音频功能的方式不同(如果是这样,我不想碰!:))。

那么,什么是最好的方法来存储和并发流传入的音频数据(MP3或OGG)从远程服务器,而不会丢弃数据?最好使用Android 2.2或更高版本,但对任何可用API的输入将不胜感激。

回答

1

建立本地代理是最好的选择。我没有看过NPR的例子,但我用Naga做过类似的事情。看到我的回答here