提交 56c89d19 编写于 作者: S shuyu

增加https在exoplayer模式下增加忽略ssl证书支持

升级 exoplayer 到 2.9.6
上级 fa4c4758
......@@ -38,6 +38,9 @@ public class GSYApplication extends MultiDexApplication {
//GSYVideoType.enableMediaCodecTexture();
//PlayerFactory.setPlayManager(Exo2PlayerManager.class);//EXO模式
//ExoSourceManager.setSkipSSLChain(true);
//PlayerFactory.setPlayManager(SystemPlayerManager.class);//系统模式
//PlayerFactory.setPlayManager(IjkPlayerManager.class);//ijk模式
......
......@@ -34,7 +34,7 @@ ext {
gsyVideoVersion = '7.0.0-beta1'
exo_player2 = '2.9.5'
exo_player2 = '2.9.6'
permissionsdispatcher = '4.3.0'
......
......@@ -4,6 +4,8 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.net.Uri;
import androidx.annotation.Nullable;
import tv.danmaku.ijk.media.exo2.source.GSYExoHttpDataSourceFactory;
import android.text.TextUtils;
import com.google.android.exoplayer2.C;
......@@ -46,8 +48,11 @@ public class ExoSourceManager {
public static final int TYPE_RTMP = 4;
private static Cache mCache;
/**
* 忽律Https证书校验
*/
private static boolean mSkipSSLChain = false;
private Context mAppContext;
......@@ -217,6 +222,19 @@ public class ExoSourceManager {
return isCached;
}
public static boolean isSkipSSLChain() {
return mSkipSSLChain;
}
/**
* 设置https忽略证书
* @param skipSSLChain true时是hulve
*/
public static void setSkipSSLChain(boolean skipSSLChain) {
mSkipSSLChain = skipSSLChain;
}
/**
* 获取SourceFactory,是否带Cache
*/
......@@ -240,6 +258,16 @@ public class ExoSourceManager {
}
private DataSource.Factory getHttpDataSourceFactory(Context context, boolean preview) {
if(mSkipSSLChain) {
GSYExoHttpDataSourceFactory dataSourceFactory = new GSYExoHttpDataSourceFactory(Util.getUserAgent(context,
TAG), preview ? null : new DefaultBandwidthMeter());
if (mMapHeadData != null && mMapHeadData.size() > 0) {
for (Map.Entry<String, String> header : mMapHeadData.entrySet()) {
dataSourceFactory.getDefaultRequestProperties().set(header.getKey(), header.getValue());
}
}
return dataSourceFactory;
}
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(context,
TAG), preview ? null : new DefaultBandwidthMeter());
if (mMapHeadData != null && mMapHeadData.size() > 0) {
......
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tv.danmaku.ijk.media.exo2.source;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource.BaseFactory;
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
import com.google.android.exoplayer2.upstream.TransferListener;
import androidx.annotation.Nullable;
/**
A {@link Factory} that produces {@link GSYExoHttpDataSource} instances.
*/
public final class GSYExoHttpDataSourceFactory extends BaseFactory {
private final String userAgent;
private final @Nullable
TransferListener listener;
private final int connectTimeoutMillis;
private final int readTimeoutMillis;
private final boolean allowCrossProtocolRedirects;
/**
Constructs a GSYExoHttpDataSourceFactory. Sets {@link
GSYExoHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link
GSYExoHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
cross-protocol redirects.
@param userAgent The User-Agent string that should be used.
*/
public GSYExoHttpDataSourceFactory(String userAgent) {
this(userAgent, null);
}
/**
Constructs a GSYExoHttpDataSourceFactory. Sets {@link
GSYExoHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link
GSYExoHttpDataSource#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 #GSYExoHttpDataSourceFactory(String, TransferListener, int, int, boolean)
*/
public GSYExoHttpDataSourceFactory(String userAgent, @Nullable TransferListener listener) {
this(userAgent, listener, GSYExoHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
GSYExoHttpDataSource.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 GSYExoHttpDataSourceFactory(
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 GSYExoHttpDataSourceFactory(
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;
}
@Override
protected GSYExoHttpDataSource createDataSourceInternal(
HttpDataSource.RequestProperties defaultRequestProperties) {
GSYExoHttpDataSource dataSource =
new GSYExoHttpDataSource(
userAgent,
/* contentTypePredicate= */ null,
connectTimeoutMillis,
readTimeoutMillis,
allowCrossProtocolRedirects,
defaultRequestProperties);
if (listener != null) {
dataSource.addTransferListener(listener);
}
return dataSource;
}
}
......@@ -35,8 +35,8 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//api project(':gsyVideoPlayer-java')
//api project(':gsyVideoPlayer-exo_player2')
api project(':gsyVideoPlayer-java')
api project(':gsyVideoPlayer-exo_player2')
//api project(':gsyVideoPlayer-armv5')
//api project(':gsyVideoPlayer-armv7a')
//api project(':gsyVideoPlayer-armv64')
......@@ -48,8 +48,8 @@ dependencies {
//api "com.shuyu:GSYVideoPlayer:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-java:$gsyVideoVersion"
api "com.shuyu:GSYVideoPlayer-exo2:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-java:$gsyVideoVersion"
//api "com.shuyu:GSYVideoPlayer-exo2:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-armv5:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-armv7a:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-arm64:$gsyVideoVersion"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册