-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): add exo external player support
- Loading branch information
1 parent
a22d75d
commit 150381d
Showing
37 changed files
with
3,907 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
31 changes: 31 additions & 0 deletions
31
platform/Android/source/ExternalPlayerExoLibrary/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.0" | ||
|
||
defaultConfig { | ||
minSdkVersion 14 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: "libs", include: ["*.jar"]) | ||
|
||
implementation project(':premierlibrary') | ||
|
||
//ExoPlayer | ||
implementation 'com.google.android.exoplayer:exoplayer:2.9.6' | ||
implementation 'com.android.support:support-annotations:28.0.0' | ||
} |
Empty file.
21 changes: 21 additions & 0 deletions
21
platform/Android/source/ExternalPlayerExoLibrary/proguard-rules.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
5 changes: 5 additions & 0 deletions
5
platform/Android/source/ExternalPlayerExoLibrary/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.aliyun.externalplayer.exo"> | ||
|
||
/ | ||
</manifest> |
145 changes: 145 additions & 0 deletions
145
...erExoLibrary/src/main/java/com/aliyun/externalplayer/exo/ExternHttpDataSourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package com.aliyun.externalplayer.exo; | ||
|
||
import android.support.annotation.Nullable; | ||
import android.text.TextUtils; | ||
|
||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource; | ||
import com.google.android.exoplayer2.upstream.HttpDataSource; | ||
import com.google.android.exoplayer2.upstream.TransferListener; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ExternHttpDataSourceFactory extends HttpDataSource.BaseFactory { | ||
|
||
private final @Nullable | ||
TransferListener listener; | ||
private final boolean allowCrossProtocolRedirects; | ||
List<String> mHttpHeaders = new ArrayList<>(); | ||
private String userAgent; | ||
private int connectTimeoutMillis; | ||
private int readTimeoutMillis; | ||
|
||
public ExternHttpDataSourceFactory() { | ||
this(ExternHttpDataSourceFactory.class.getSimpleName(), null); | ||
} | ||
|
||
/** | ||
* Constructs a DefaultHttpDataSourceFactory. Sets {@link | ||
* DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link | ||
* DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables | ||
* cross-protocol redirects. | ||
* | ||
* @param userAgent The User-Agent string that should be used. | ||
*/ | ||
public ExternHttpDataSourceFactory(String userAgent) { | ||
this(userAgent, null); | ||
} | ||
|
||
/** | ||
* Constructs a DefaultHttpDataSourceFactory. Sets {@link | ||
* DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link | ||
* DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables | ||
* cross-protocol redirects. | ||
* | ||
* @param userAgent The User-Agent string that should be used. | ||
* @param listener An optional listener. | ||
* @see #ExternHttpDataSourceFactory(String, TransferListener, int, int, boolean) | ||
*/ | ||
public ExternHttpDataSourceFactory(String userAgent, @Nullable TransferListener listener) { | ||
this(userAgent, listener, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, | ||
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, false); | ||
} | ||
|
||
/** | ||
* @param userAgent The User-Agent string that should be used. | ||
* @param connectTimeoutMillis The connection timeout that should be used when requesting remote | ||
* data, in milliseconds. A timeout of zero is interpreted as an infinite timeout. | ||
* @param readTimeoutMillis The read timeout that should be used when requesting remote data, in | ||
* milliseconds. A timeout of zero is interpreted as an infinite timeout. | ||
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP | ||
* to HTTPS and vice versa) are enabled. | ||
*/ | ||
public ExternHttpDataSourceFactory( | ||
String userAgent, | ||
int connectTimeoutMillis, | ||
int readTimeoutMillis, | ||
boolean allowCrossProtocolRedirects) { | ||
this( | ||
userAgent, | ||
/* listener= */ null, | ||
connectTimeoutMillis, | ||
readTimeoutMillis, | ||
allowCrossProtocolRedirects); | ||
} | ||
|
||
/** | ||
* @param userAgent The User-Agent string that should be used. | ||
* @param listener An optional listener. | ||
* @param connectTimeoutMillis The connection timeout that should be used when requesting remote | ||
* data, in milliseconds. A timeout of zero is interpreted as an infinite timeout. | ||
* @param readTimeoutMillis The read timeout that should be used when requesting remote data, in | ||
* milliseconds. A timeout of zero is interpreted as an infinite timeout. | ||
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP | ||
* to HTTPS and vice versa) are enabled. | ||
*/ | ||
public ExternHttpDataSourceFactory( | ||
String userAgent, | ||
@Nullable TransferListener listener, | ||
int connectTimeoutMillis, | ||
int readTimeoutMillis, | ||
boolean allowCrossProtocolRedirects) { | ||
this.userAgent = userAgent; | ||
this.listener = listener; | ||
this.connectTimeoutMillis = connectTimeoutMillis; | ||
this.readTimeoutMillis = readTimeoutMillis; | ||
this.allowCrossProtocolRedirects = allowCrossProtocolRedirects; | ||
} | ||
|
||
public void addHttpHeaders(String httpHeader) { | ||
if (!TextUtils.isEmpty(httpHeader)) { | ||
mHttpHeaders.add(httpHeader); | ||
} | ||
} | ||
|
||
public void clearHttpHeaders() { | ||
mHttpHeaders.clear(); | ||
} | ||
|
||
public void setConnectTimeoutMillis(int timeoutMillis) { | ||
connectTimeoutMillis = timeoutMillis; | ||
} | ||
|
||
public void setReadTimeoutMillis(int timeoutMillis) { | ||
readTimeoutMillis = timeoutMillis; | ||
} | ||
|
||
@Override | ||
protected DefaultHttpDataSource createDataSourceInternal( | ||
HttpDataSource.RequestProperties defaultRequestProperties) { | ||
DefaultHttpDataSource dataSource = | ||
new DefaultHttpDataSource( | ||
TextUtils.isEmpty(userAgent) ? ExternHttpDataSourceFactory.class.getSimpleName() : userAgent, | ||
/* contentTypePredicate= */ null, | ||
connectTimeoutMillis, | ||
readTimeoutMillis, | ||
allowCrossProtocolRedirects, | ||
defaultRequestProperties); | ||
for (String header : mHttpHeaders) { | ||
String[] keyValue = header.split(":"); | ||
if (keyValue.length != 2) { | ||
continue; | ||
} | ||
dataSource.setRequestProperty(keyValue[0], keyValue[1]); | ||
} | ||
|
||
if (listener != null) { | ||
dataSource.addTransferListener(listener); | ||
} | ||
return dataSource; | ||
} | ||
|
||
public void setUserAgent(String userAgent) { | ||
this.userAgent = userAgent; | ||
} | ||
} |
Oops, something went wrong.