Skip to content

Commit

Permalink
CarGuo#2922 deprecated SkipSSLChain ,support api custom dataSoucre
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Aug 27, 2020
1 parent d3a382b commit c8398b4
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ protected void onCreate(Bundle savedInstanceState) {
.setRotateViewAuto(false)
//仅仅横屏旋转,不变直
//.setOnlyRotateLand(true)
.setLockLand(false)
.setAutoFullWithSize(false)
.setLockLand(true)
.setAutoFullWithSize(true)
.setShowFullAnimation(false)
.setNeedLockFull(true)
.setUrl(url)
Expand Down Expand Up @@ -317,7 +317,7 @@ private String getUrl() {
//String url = "http://video.7k.cn/app_video/20171202/6c8cf3ea/v.m3u8.mp4";
//String url = "http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8";
//String url = "rtmp://ctc-zhenjiang04.rt1.gensee.com/5324e855b28b453db7b0ec226598b76c_171391_0_8801038305_1591077225_205d01b8/video";
String url = "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4";
String url = "http://video1.dgtle.com/backend%2F2020%2F3%2F0%2F%E6%88%91%E6%B2%A1%E6%9C%89%E7%BB%99%E4%B8%80%E5%8A%A08Pro%E5%81%9A%E8%AF%84%E6%B5%8B_%E5%8D%B4%E5%B8%A6%E7%9D%80%E5%AE%83%E6%BC%82%E6%B5%81.mp4_1080.mp4";
//String url = "http://yongtaizx.xyz/20191230/t2Axgh3k/index.m3u8";
//String url = "https://pointshow.oss-cn-hangzhou.aliyuncs.com/McTk51586843620689.mp4";
//String url = "http://pointshow.oss-cn-hangzhou.aliyuncs.com/transcode/ORIGINAL/Mnbc61586842828593.mp4";
Expand Down
33 changes: 25 additions & 8 deletions app/src/main/java/com/example/gsyvideoplayer/GSYApplication.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package com.example.gsyvideoplayer;

import androidx.annotation.Nullable;
import androidx.multidex.MultiDexApplication;

import tv.danmaku.ijk.media.exo2.Exo2PlayerManager;
import tv.danmaku.ijk.media.exo2.ExoMediaSourceInterceptListener;
import tv.danmaku.ijk.media.exo2.ExoSourceManager;
import tv.danmaku.ijk.media.exo2.IjkExo2MediaPlayer;
import tv.danmaku.ijk.media.player.IMediaPlayer;

import com.example.gsyvideoplayer.source.GSYExoHttpDataSourceFactory;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.TransferListener;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.model.GSYModel;
import com.shuyu.gsyvideoplayer.player.BasePlayerManager;
Expand All @@ -18,6 +26,8 @@
import com.shuyu.gsyvideoplayer.utils.GSYVideoType;
import com.squareup.leakcanary.LeakCanary;

import java.io.File;

import static com.google.android.exoplayer2.util.Util.inferContentType;

/**
Expand Down Expand Up @@ -61,18 +71,25 @@ public void onCreate() {

//IjkPlayerManager.setLogLevel(IjkMediaPlayer.IJK_LOG_SILENT);

/*ExoSourceManager.setExoMediaSourceInterceptListener(new ExoMediaSourceInterceptListener() {
ExoSourceManager.setExoMediaSourceInterceptListener(new ExoMediaSourceInterceptListener() {
@Override
public MediaSource getMediaSource(String dataSource, boolean preview, boolean cacheEnable, boolean isLooping, File cacheDir) {
Uri contentUri = Uri.parse(dataSource);
int contentType = inferContentType(dataSource);
switch (contentType) {
case C.TYPE_HLS:
return new HlsMediaSource.Factory(CustomSourceTag.getDataSourceFactory(GSYApplication.this.getApplicationContext(), preview)).createMediaSource(contentUri);
}
//如果返回 null,就使用默认的
return null;
}
});*/

/**
* 通过自定义的 HttpDataSource ,可以设置自签证书或者忽略证书
* demo 里的 GSYExoHttpDataSourceFactory 使用的是忽略证书
* */
@Override
public HttpDataSource.BaseFactory getHttpDataSourceFactory(String userAgent, @Nullable TransferListener listener, int connectTimeoutMillis, int readTimeoutMillis, boolean allowCrossProtocolRedirects) {
//如果返回 null,就使用默认的
return new GSYExoHttpDataSourceFactory(userAgent, listener,
connectTimeoutMillis,
readTimeoutMillis, allowCrossProtocolRedirects);
}
});

/*GSYVideoManager.instance().setPlayerInitSuccessListener(new IPlayerInitSuccessListener() {
///播放器初始化成果回调
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tv.danmaku.ijk.media.exo2.source;
package com.example.gsyvideoplayer.source;

import android.net.Uri;
import android.text.TextUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tv.danmaku.ijk.media.exo2.source;
package com.example.gsyvideoplayer.source;

import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource.BaseFactory;
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package tv.danmaku.ijk.media.exo2;

import androidx.annotation.Nullable;

import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.TransferListener;

import java.io.File;

Expand All @@ -19,4 +23,15 @@ public interface ExoMediaSourceInterceptListener {
* @return 返回不为空时,使用返回的自定义mediaSource
*/
MediaSource getMediaSource(String dataSource, boolean preview, boolean cacheEnable, boolean isLooping, File cacheDir);


/**
* @return 返回不为空时,使用返回的自定义 HttpDataSource
*/
HttpDataSource.BaseFactory getHttpDataSourceFactory(
String userAgent,
@Nullable TransferListener listener,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

import androidx.annotation.Nullable;

import tv.danmaku.ijk.media.exo2.source.GSYDefaultHttpDataSource;
import tv.danmaku.ijk.media.exo2.source.GSYExoHttpDataSourceFactory;

import android.text.TextUtils;

import com.google.android.exoplayer2.C;
Expand All @@ -26,7 +23,9 @@
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
import com.google.android.exoplayer2.upstream.cache.Cache;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
Expand Down Expand Up @@ -57,7 +56,9 @@ public class ExoSourceManager {
private static Cache mCache;
/**
* 忽律Https证书校验
* @deprecated 如果需要忽略证书,请直接使用 ExoMediaSourceInterceptListener 的 getHttpDataSourceFactory
*/
@Deprecated
private static boolean sSkipSSLChain = false;

private static int sHttpReadTimeout = -1;
Expand Down Expand Up @@ -259,7 +260,11 @@ public boolean hadCached() {
return isCached;
}


/**
* 忽律Https证书校验
* @deprecated 如果需要忽略证书,请直接使用 ExoMediaSourceInterceptListener 的 getHttpDataSourceFactory
*/
@Deprecated
public static boolean isSkipSSLChain() {
return sSkipSSLChain;
}
Expand All @@ -268,7 +273,9 @@ public static boolean isSkipSSLChain() {
* 设置https忽略证书
*
* @param skipSSLChain true时是hulve
* @deprecated 如果需要忽略证书,请直接使用 ExoMediaSourceInterceptListener 的 getHttpDataSourceFactory
*/
@Deprecated
public static void setSkipSSLChain(boolean skipSSLChain) {
sSkipSSLChain = skipSSLChain;
}
Expand Down Expand Up @@ -322,8 +329,8 @@ private DataSource.Factory getHttpDataSourceFactory(Context context, boolean pre
if (uerAgent == null) {
uerAgent = Util.getUserAgent(context, TAG);
}
int connectTimeout = GSYDefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS;
int readTimeout = GSYDefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS;
int connectTimeout = DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS;
int readTimeout = DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS;
if (sHttpConnectTimeout > 0) {
connectTimeout = sHttpConnectTimeout;
}
Expand All @@ -334,20 +341,16 @@ private DataSource.Factory getHttpDataSourceFactory(Context context, boolean pre
if (mMapHeadData != null && mMapHeadData.size() > 0) {
allowCrossProtocolRedirects = "true".equals(mMapHeadData.get("allowCrossProtocolRedirects"));
}
if (sSkipSSLChain) {
GSYExoHttpDataSourceFactory dataSourceFactory = new GSYExoHttpDataSourceFactory(uerAgent, preview ? null : new DefaultBandwidthMeter.Builder(mAppContext).build(),
HttpDataSource.BaseFactory dataSourceFactory;
if (sExoMediaSourceInterceptListener != null) {
dataSourceFactory = sExoMediaSourceInterceptListener.getHttpDataSourceFactory(uerAgent, preview ? null : new DefaultBandwidthMeter.Builder(mAppContext).build(),
connectTimeout,
readTimeout, allowCrossProtocolRedirects);
} else {
dataSourceFactory = new DefaultHttpDataSourceFactory(uerAgent, preview ? null : new DefaultBandwidthMeter.Builder(mAppContext).build(),
connectTimeout,
readTimeout, allowCrossProtocolRedirects);
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(uerAgent, preview ? null : new DefaultBandwidthMeter.Builder(mAppContext).build(),
connectTimeout,
readTimeout, allowCrossProtocolRedirects);
if (mMapHeadData != null && mMapHeadData.size() > 0) {
for (Map.Entry<String, String> header : mMapHeadData.entrySet()) {
dataSourceFactory.getDefaultRequestProperties().set(header.getKey(), header.getValue());
Expand Down
6 changes: 3 additions & 3 deletions gsyVideoPlayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ dependencies {

//api "com.shuyu:gsyVideoPlayer-java:$gsyVideoVersion"
//api "com.shuyu:GSYVideoPlayer-exo2:$gsyVideoVersion"
// api "com.shuyu:gsyVideoPlayer-armv5:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-armv5:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-armv7a:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-arm64:$gsyVideoVersion"
// api "com.shuyu:gsyVideoPlayer-x64:$gsyVideoVersion"
// api "com.shuyu:gsyVideoPlayer-x86:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-x64:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-x86:$gsyVideoVersion"

//更多配置版so,增加了concat,rtsp,mpeg,crypto
//api "com.shuyu:gsyVideoPlayer-ex_so:$gsyVideoVersion"
Expand Down

0 comments on commit c8398b4

Please sign in to comment.