persistent caching
Closed this issue · 11 comments
Hi
I've successfully compiled and tested the project, much appreciated to those involved to keep this project going strong! I'm new to ffmpeg library and wondering if you could provide some pointer regarding my use case.
Basically, I'm trying to play audio files (mp3) off my web server and write to local cache at the same time. Can it be done in without using local proxy?
For future play back, I'll need to use input stream as datasource rather than file datasource. I notice that you have kindly added custom datasource support but just want to check it's appropriate for my use case.
Any help will be greatly appreciated.
Leo
I think it's supposed to work like that. It would follow the behavior of
http://developer.android.com/intl/zh-cn/reference/android/media/MediaDataSource.html
Thanks for the reply. Does it mean I need to use custom datasource for both
situations? (i.e caching stream and inputstream playback).
Cheers
On 16 Feb 2016 03:04, "bbcallen" notifications@github.com wrote:
I think it's supposed to work like that. It would follow the behavior of
http://developer.android.com/intl/zh-cn/reference/android/media/MediaDataSource.html
—
Reply to this email directly or view it on GitHub
#916 (comment).
Yes, if you want more control.
Thanks for the reply. I have managed to get custom datasource working for local files, but don't have a clue where to start for http datasource. All I want to do is retrieve the file from url, play it back when there's enough buffer and write buffer to local storage at the same time. Any pointer will be much appreciated. Thanks in advance.
I don't understand. ijkplayer doesn't care what is behind MediaDataSource, what url it is from, whether it is saved to local storage. It only get data with readAt() and getSize(). You can do everything you want under that.
Sorry for confusion. I'm new to android development and my knowledge is limited. Please find below code for httpmediasource which I'm currently using to read the mp3 from http server. It doesn't seem to work at the moment and most likely I'm not doing it right! Just wondering if you could provide a sample or any information to retrieve the file from url using custom datasource and feed it to the player.
Many Thanks
public class httpMediaSource implements IMediaDataSource {
InputStream inputStream;
public httpMediaSource() throws MalformedURLException {
String fileURL = "http://thesixteendigital.com.s3.amazonaws.com/testfiles/Hallelujah.mp3";
URL url = new URL(fileURL);
HttpURLConnection httpConn = null;
try {
httpConn = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
try {
int responseCode = httpConn.getResponseCode();
} catch (IOException e) {
e.printStackTrace();
}
try {
inputStream = httpConn.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public int readAt(long position, byte[] bytes, int offset, int size) throws IOException {
return inputStream.read(bytes,offset,size);
}
@Override
public long getSize() throws IOException {
return inputStream.available();
}
@Override
public void close() throws IOException {
if (inputStream != null) {
inputStream.close();
}
inputStream = null;
}
}
@Override
public int readAt(long position, byte[] bytes, int offset, int size) throws IOException {
// the position is not always continuous, you should remember you current position
// and adjust it to the requested position.
return inputStream.read(bytes,offset,size);
}
@Override
public long getSize() throws IOException {
// you need to retrieve "Content Length" from http client (if any)
// and return it as size, or return -1, if size is not available.
return inputStream.available();
}
Thanks for the reply. I will give it a try and see how it goes. I believe
it will be useful to include in sample project for future reference.
Many thanks.
On 17 Feb 2016 12:01, "bbcallen" notifications@github.com wrote:
@OverRide
public int readAt(long position, byte[] bytes, int offset, int size) throws IOException {
// the position is not always continuous, you should remember you current position
// and adjust it to the requested position.
return inputStream.read(bytes,offset,size);
}@Override public long getSize() throws IOException { // you need to retrieve "Content Length" from http client (if any) // and return it as size, or return -1, if size is not available. return inputStream.available(); }
—
Reply to this email directly or view it on GitHub
#916 (comment).
@laminsk Hi, I am trying to play a video from my server, I want to know whether you have implemented IMediaDataSource successfully. If you have a successful implementation, please share the java class. It will be very helpful. Thank you.
@midoreigh I haven't managed to get seek working yet but I use okhttp datasource for exolplayer and tweaked it. Good luck and let me know if you managed to solve seek problem while saving the stream. https://github.com/google/ExoPlayer/blob/master/extensions/okhttp/src/main/java/com/google/android/exoplayer/ext/okhttp/OkHttpDataSource.java