我正在使用套接字作为MediaPlayer的代理,因此我可以在将mp3音频写入套接字之前下载并解密它.这类似于NPR新闻应用程序中显示的示例,但是我将其用于所有Android版本2.1 - 4 atm.
NPR StreamProxy代码 - http://code.google.com/p/npr-android-app/source/browse/Npr/src/org/npr/android/news/StreamProxy.java
我的问题是2.1-2.3的播放速度很快,但在Android 4.0 ICS中,MediaPlayer在触发onPrepared监听器之前会缓冲太多数据.
在onPrepared()之前写入Socket OutputStream的示例数据量:
在SGS2上有2.3.4 - onPrepared()在~133920字节之后
在Nexus S上使用4.0.4 - onPrepared()在~961930字节之后
这也发生在Galaxy Nexus上.
奇怪的是,4.0模拟器不会像4.0设备一样缓冲数据.有人在ICS上遇到与MediaPlayer类似的问题吗?
编辑
以下是代理如何写入套接字.在这个例子中,它来自从文件加载的CipherInputStream,但是当它从HttpResponse加载时也是如此.
final Socket client = (setup above)
// encrypted file input stream
final CipherInputStream inputStream = getInputStream(file);
// setup the socket output stream
final OutputStream output = client.getOutputStream();
// Writing the header
final String httpHeader = buildHttpHeader(file.length());
final byte[] buffer = httpHeader.getBytes("UTF-8");
output.write(buffer, 0, buffer.length);
int writtenBytes = 0;
int readBytes;
final byte[] buff = new …Run Code Online (Sandbox Code Playgroud)