-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an extension that provide DataSource using OkHttp #735
Conversation
Not sure where should I write a demo for it, cause I need to rewrite all render builder in demo app. |
I don't think it needs a demo app. It would be trivial for someone to swap it into the normal demo app in a couple of minutes, if they want to experiment with it, so I don't think it needs a demo of its own. |
👍 Tried this, swapping into the I love that it can integrate with the OkHttp's Thank you @b95505017 ! |
@talklittle You could also integrate Stetho via OkHttp's Interceptor mechanism, then all request could monitor via chrome dev tool. |
We're finalizing a 1.5.x release at the moment. We'll be merging it after that's done. Sorry for the long delay; perhaps we need more branches :). Thanks! |
1.5.0 is out, so we're pretty much ready to merge this. Our plan is to merge it as-is, since it looks in pretty good shape already and works well. Just FYI, we then plan to make some follow-up modifications, including:
|
Add an extension that provide DataSource using OkHttp
This is now merged, with the modifications described above applied. Please take a look and check that it still needs the original needs. Thanks! |
LGTM 👍 :) |
@b95505017, thanks for this OkHttp version. @talklittle can you share how you set this up to get caching working with mp4s? Are you working with partial responses at all? |
@TommyVisic Nothing fancy at all, just setting a Cache on the OkHttpClient. EDIT: Depending on server configuration, specifically if the server supports HTTP 206 partial responses, then OkHttp cache won't handle it. The solution I came up with was:
Or see comment by @econnelly for a couple other potential solutions. |
@TommyVisic take a look with OkHttp recipes |
The ReadMe for the OkHttp Extension doesn't have any build instructions. I'm assuming this is similar to how other extensions are built? Anyone with more experience care to comment on the process of including it in a project? Any info would greatly be appreciated! Would be nice to have some way of just adding a single Oh, awesome extension by the way! Really helps considering that caching still seems to be quite a bit of work to set up. |
Yes just using Just like the usage of DefaultHttpDataSource.java, if you really need an example then I could provide it. :) |
Adding a line to the settings.gradle will get it compile into the build, but we still need to program the app to use okhttp instead default one. There is no magic (like reflection) to pick up the okhttp. |
OK I'll try to write an example AOAP. |
@talklittle OkHttp doesn't cache partial requests. The OkHttp cach may work on a fast connection where the entire file can be downloaded in one shot, but it's not reliable. I just went through the exact scenario where a looping mp4 was redownloading every time it started over. There are two ways to prevent this.
|
@econnelly Hey thanks for pointing that out. Another way is by forcing OkHttp to request the full file each time using a network interceptor and removing the I'll update my other comment for posterity. |
Thanks, @talklittle, @econnelly, @b95505017, and @brianchu for the extra info. It's been very insightful. I feel like I'm getting tripped up in the set up here, as my IDE (Android Studio) doesn't seem to auto-complete Does someone mind sharing their Gradle? |
@kwelsh Copy the file into your project. It's not in the Maven artifact on JCenter. You can verify this in Android Studio in the Project view: External Libraries -> exoplayer-r1.5.2 -> classes.jar. The extensions are not included. The Maven artifact corresponds to the |
Here is my example which replace demo data source with OkHttp, default is no cache. |
@talklittle Ah I see. Thanks for clarifying this. @b95505017 That is awesome! It seems a lot simpler than I envisioned in my head. I'm gonna give this another go. |
I got this thing up and running. Just need to configure it to cache now. Thanks again, everyone. |
@kwelsh just a heads up, partial requests are not cached. If you modify the method makeRequest in OkHttpDataSource you can get caching to work correctly. |
@laurencedawson Thanks for the heads up. I'm still struggling with getting caching to work on the demo for ExoPlayer. I've added in OkHttp to handle the networking requests, but it still seems to re-download the video when you rotate the screen or power off (anything that recreates the fragment again). I'd be extremely interested in your solution, if just to see a different perspective on the matter! :) |
You could inject your own CacheControl (or just give it |
I'v upgrade the extension to supporting okhttp3 #1119 |
Thank you b95505017 and everyone for valuable inputs. I've been trying to download audio stream from server to disk using okhttpdatasource and still no luck so far. Has anyone manage to do this yet? Any help would be greatly appreciated. Thanks in advance. |
What do you mean about "no luck"? |
Hi I want to cache an mp4. it seems that in OkHttpDataSource on makeRequest the DataSpec has an unbounded length and this makes it to download the file every time because it cannot cache it. |
@talklittle so you made cache work for mp4s ? can you please elaborate? |
#524