Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
93c2133f
authored
Oct 09, 2016
by
ojw28
Committed by
GitHub
Oct 09, 2016
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge pull request #1909 from kaorimatz/okhttp-call-factory
Use Call.Factory instead of OkHttpClient
parents
6c12ec62
880bdc18
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
20 deletions
extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java
extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSourceFactory.java
extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.java
View file @
93c2133f
...
...
@@ -32,21 +32,21 @@ import java.util.List;
import
java.util.Map
;
import
java.util.concurrent.atomic.AtomicReference
;
import
okhttp3.CacheControl
;
import
okhttp3.Call
;
import
okhttp3.HttpUrl
;
import
okhttp3.MediaType
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.RequestBody
;
import
okhttp3.Response
;
/**
* An {@link HttpDataSource} that delegates to Square's {@link
OkHttpClient
}.
* An {@link HttpDataSource} that delegates to Square's {@link
Call.Factory
}.
*/
public
class
OkHttpDataSource
implements
HttpDataSource
{
private
static
final
AtomicReference
<
byte
[]>
skipBufferReference
=
new
AtomicReference
<>();
private
final
OkHttpClient
okHttpClient
;
private
final
Call
.
Factory
callFactory
;
private
final
String
userAgent
;
private
final
Predicate
<
String
>
contentTypePredicate
;
private
final
TransferListener
<?
super
OkHttpDataSource
>
listener
;
...
...
@@ -65,31 +65,31 @@ public class OkHttpDataSource implements HttpDataSource {
private
long
bytesRead
;
/**
* @param c
lient An {@link OkHttpClient
} for use by the source.
* @param c
allFactory An {@link Call.Factory
} for use by the source.
* @param userAgent The User-Agent string that should be used.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then a InvalidContentTypeException} is thrown from {@link #open(DataSpec)}.
*/
public
OkHttpDataSource
(
OkHttpClient
client
,
String
userAgent
,
public
OkHttpDataSource
(
Call
.
Factory
callFactory
,
String
userAgent
,
Predicate
<
String
>
contentTypePredicate
)
{
this
(
c
lient
,
userAgent
,
contentTypePredicate
,
null
);
this
(
c
allFactory
,
userAgent
,
contentTypePredicate
,
null
);
}
/**
* @param c
lient An {@link OkHttpClient
} for use by the source.
* @param c
allFactory An {@link Call.Factory
} for use by the source.
* @param userAgent The User-Agent string that should be used.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then a {@link InvalidContentTypeException} is thrown from
* {@link #open(DataSpec)}.
* @param listener An optional listener.
*/
public
OkHttpDataSource
(
OkHttpClient
client
,
String
userAgent
,
public
OkHttpDataSource
(
Call
.
Factory
callFactory
,
String
userAgent
,
Predicate
<
String
>
contentTypePredicate
,
TransferListener
<?
super
OkHttpDataSource
>
listener
)
{
this
(
c
lient
,
userAgent
,
contentTypePredicate
,
listener
,
null
);
this
(
c
allFactory
,
userAgent
,
contentTypePredicate
,
listener
,
null
);
}
/**
* @param c
lient An {@link OkHttpClient
} for use by the source.
* @param c
allFactory An {@link Call.Factory
} for use by the source.
* @param userAgent The User-Agent string that should be used.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then a {@link InvalidContentTypeException} is thrown from
...
...
@@ -98,10 +98,10 @@ public class OkHttpDataSource implements HttpDataSource {
* @param cacheControl An optional {@link CacheControl} which sets all requests' Cache-Control
* header. For example, you could force the network response for all requests.
*/
public
OkHttpDataSource
(
OkHttpClient
client
,
String
userAgent
,
public
OkHttpDataSource
(
Call
.
Factory
callFactory
,
String
userAgent
,
Predicate
<
String
>
contentTypePredicate
,
TransferListener
<?
super
OkHttpDataSource
>
listener
,
CacheControl
cacheControl
)
{
this
.
okHttpClient
=
Assertions
.
checkNotNull
(
client
);
this
.
callFactory
=
Assertions
.
checkNotNull
(
callFactory
);
this
.
userAgent
=
Assertions
.
checkNotEmpty
(
userAgent
);
this
.
contentTypePredicate
=
contentTypePredicate
;
this
.
listener
=
listener
;
...
...
@@ -150,7 +150,7 @@ public class OkHttpDataSource implements HttpDataSource {
this
.
bytesSkipped
=
0
;
Request
request
=
makeRequest
(
dataSpec
);
try
{
response
=
okHttpClient
.
newCall
(
request
).
execute
();
response
=
callFactory
.
newCall
(
request
).
execute
();
responseByteStream
=
response
.
body
().
byteStream
();
}
catch
(
IOException
e
)
{
throw
new
HttpDataSourceException
(
"Unable to connect to "
+
dataSpec
.
uri
.
toString
(),
e
,
...
...
extensions/okhttp/src/main/java/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSourceFactory.java
View file @
93c2133f
...
...
@@ -19,26 +19,26 @@ import com.google.android.exoplayer2.upstream.DataSource;
import
com.google.android.exoplayer2.upstream.HttpDataSource.Factory
;
import
com.google.android.exoplayer2.upstream.TransferListener
;
import
okhttp3.CacheControl
;
import
okhttp3.
OkHttpClient
;
import
okhttp3.
Call
;
/**
* A {@link Factory} that produces {@link OkHttpDataSource}.
*/
public
final
class
OkHttpDataSourceFactory
implements
Factory
{
private
final
OkHttpClient
client
;
private
final
Call
.
Factory
callFactory
;
private
final
String
userAgent
;
private
final
TransferListener
<?
super
DataSource
>
transferListener
;
private
final
CacheControl
cacheControl
;
public
OkHttpDataSourceFactory
(
OkHttpClient
client
,
String
userAgent
,
public
OkHttpDataSourceFactory
(
Call
.
Factory
callFactory
,
String
userAgent
,
TransferListener
<?
super
DataSource
>
transferListener
)
{
this
(
c
lient
,
userAgent
,
transferListener
,
null
);
this
(
c
allFactory
,
userAgent
,
transferListener
,
null
);
}
public
OkHttpDataSourceFactory
(
OkHttpClient
client
,
String
userAgent
,
public
OkHttpDataSourceFactory
(
Call
.
Factory
callFactory
,
String
userAgent
,
TransferListener
<?
super
DataSource
>
transferListener
,
CacheControl
cacheControl
)
{
this
.
c
lient
=
client
;
this
.
c
allFactory
=
callFactory
;
this
.
userAgent
=
userAgent
;
this
.
transferListener
=
transferListener
;
this
.
cacheControl
=
cacheControl
;
...
...
@@ -46,7 +46,7 @@ public final class OkHttpDataSourceFactory implements Factory {
@Override
public
OkHttpDataSource
createDataSource
()
{
return
new
OkHttpDataSource
(
c
lient
,
userAgent
,
null
,
transferListener
,
cacheControl
);
return
new
OkHttpDataSource
(
c
allFactory
,
userAgent
,
null
,
transferListener
,
cacheControl
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment