MediaPlayer cannot use the InputStream as DataSource. what I want is I can reduce or discard the MediaPlayer prepared time, so I need cache the stream to a file. When the target Sdk >= 23, I can Use
mMediaPlayer.setDataSource(new MediaDataSource() {
@Override
public int readAt(long position, byte[] buffer, int offset, int size) throws IOException {
return 0;
}
@Override
public long getSize() throws IOException {
return 0;
}
@Override
public void close() throws IOException {
}
});
but how to make it work at the lower target. Now, I have researched two ways:
1:Just like NanoHttp cache stream , build a local server, convert the remote url to local url, and use setDataSource(localUri)
2:Cache the video head to a local file, but the FileDescriptor cannot be read over the writing time. There are other data structure could be read and write meanwhile?
Do you have better idea?
Could anybody help me ?