1*30877f79SAndroid Build Coastguard Worker# OkHttp DataSource module 2*30877f79SAndroid Build Coastguard Worker 3*30877f79SAndroid Build Coastguard WorkerThis module provides an [HttpDataSource][] implementation that uses Square's 4*30877f79SAndroid Build Coastguard Worker[OkHttp][]. 5*30877f79SAndroid Build Coastguard Worker 6*30877f79SAndroid Build Coastguard WorkerOkHttp is a modern network stack that's widely used by many popular Android 7*30877f79SAndroid Build Coastguard Workerapplications. It supports the HTTP and HTTP/2 protocols. 8*30877f79SAndroid Build Coastguard Worker 9*30877f79SAndroid Build Coastguard Worker[HttpDataSource]: https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/upstream/HttpDataSource.html 10*30877f79SAndroid Build Coastguard Worker[OkHttp]: https://square.github.io/okhttp/ 11*30877f79SAndroid Build Coastguard Worker 12*30877f79SAndroid Build Coastguard Worker## License note 13*30877f79SAndroid Build Coastguard Worker 14*30877f79SAndroid Build Coastguard WorkerPlease note that whilst the code in this repository is licensed under 15*30877f79SAndroid Build Coastguard Worker[Apache 2.0][], using this extension requires depending on OkHttp, which is 16*30877f79SAndroid Build Coastguard Workerlicensed separately. 17*30877f79SAndroid Build Coastguard Worker 18*30877f79SAndroid Build Coastguard Worker[Apache 2.0]: https://github.com/google/ExoPlayer/blob/release-v2/LICENSE 19*30877f79SAndroid Build Coastguard Worker 20*30877f79SAndroid Build Coastguard Worker## Getting the module 21*30877f79SAndroid Build Coastguard Worker 22*30877f79SAndroid Build Coastguard WorkerThe easiest way to get the module is to add it as a gradle dependency: 23*30877f79SAndroid Build Coastguard Worker 24*30877f79SAndroid Build Coastguard Worker```gradle 25*30877f79SAndroid Build Coastguard Workerimplementation 'com.google.android.exoplayer:extension-okhttp:2.X.X' 26*30877f79SAndroid Build Coastguard Worker``` 27*30877f79SAndroid Build Coastguard Worker 28*30877f79SAndroid Build Coastguard Workerwhere `2.X.X` is the version, which must match the version of the other media 29*30877f79SAndroid Build Coastguard Workermodules being used. 30*30877f79SAndroid Build Coastguard Worker 31*30877f79SAndroid Build Coastguard WorkerAlternatively, you can clone this GitHub project and depend on the module 32*30877f79SAndroid Build Coastguard Workerlocally. Instructions for doing this can be found in the [top level README][]. 33*30877f79SAndroid Build Coastguard Worker 34*30877f79SAndroid Build Coastguard Worker[top level README]: https://github.com/google/ExoPlayer/blob/release-v2/README.md 35*30877f79SAndroid Build Coastguard Worker 36*30877f79SAndroid Build Coastguard Worker## Using the module 37*30877f79SAndroid Build Coastguard Worker 38*30877f79SAndroid Build Coastguard WorkerMedia components request data through `DataSource` instances. These instances 39*30877f79SAndroid Build Coastguard Workerare obtained from instances of `DataSource.Factory`, which are instantiated and 40*30877f79SAndroid Build Coastguard Workerinjected from application code. 41*30877f79SAndroid Build Coastguard Worker 42*30877f79SAndroid Build Coastguard WorkerIf your application only needs to play http(s) content, using the OkHttp 43*30877f79SAndroid Build Coastguard Workerextension is as simple as updating any `DataSource.Factory` instantiations in 44*30877f79SAndroid Build Coastguard Workeryour application code to use `OkHttpDataSource.Factory`. If your application 45*30877f79SAndroid Build Coastguard Workeralso needs to play non-http(s) content such as local files, use: 46*30877f79SAndroid Build Coastguard Worker``` 47*30877f79SAndroid Build Coastguard Workernew DefaultDataSourceFactory( 48*30877f79SAndroid Build Coastguard Worker ... 49*30877f79SAndroid Build Coastguard Worker /* baseDataSourceFactory= */ new OkHttpDataSource.Factory(...)); 50*30877f79SAndroid Build Coastguard Worker``` 51*30877f79SAndroid Build Coastguard Worker 52*30877f79SAndroid Build Coastguard Worker## Links 53*30877f79SAndroid Build Coastguard Worker 54*30877f79SAndroid Build Coastguard Worker* [Javadoc][] 55*30877f79SAndroid Build Coastguard Worker 56*30877f79SAndroid Build Coastguard Worker[Javadoc]: https://exoplayer.dev/doc/reference/index.html 57