改为EXOPlayer

This commit is contained in:
zlzw 2022-10-31 15:48:42 +08:00
parent 7e9b794c7f
commit f856188a68
3 changed files with 33 additions and 110 deletions

View File

@ -1 +1 @@
apply plugin: 'com.android.library' apply plugin: 'img-optimizer' apply plugin: 'kotlin-android' android { compileSdkVersion rootProject.ext.android.compileSdkVersion buildToolsVersion rootProject.ext.android.buildToolsVersion aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false packagingOptions { pickFirst "lib/armeabi/libyuvutils.so" pickFirst "lib/arm64-v8a/libyuvutils.so" pickFirst "lib/armeabi-v7a/libyuvutils.so" pickFirst "lib/armeabi/libyuvtools.so" pickFirst "lib/arm64-v8a/libyuvtools.so" pickFirst "lib/armeabi-v7a/libyuvtools.so" exclude "lib/arm64-v8a/libmmcv_api_handgesture.so" exclude "lib/arm64-v8a/libmmcv_api_express.so" exclude "lib/arm64-v8a/libMediaEncoder.so" exclude "lib/arm64-v8a/libarcore_sdk_c.so" exclude "lib/arm64-v8a/libmediadecoder.so" exclude "lib/arm64-v8a/libMediaMuxer.so" exclude "lib/arm64-v8a/libarcore_sdk_jni.so" exclude "lib/arm64-v8a/libMediaUtils.so" exclude "lib/arm64-v8a/libcosmosffmpeg.so" } defaultConfig { minSdkVersion rootProject.ext.android.minSdkVersion targetSdkVersion rootProject.ext.android.targetSdkVersion versionCode rootProject.ext.android.versionCode versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { abiFilters "armeabi-v7a", "arm64-v8a" } javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] } } } aaptOptions { cruncherEnabled = false useNewCruncher = false } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } kotlinOptions { allWarningsAsErrors = true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } repositories { flatDir { dirs 'libs', '../libs' } mavenCentral() } dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.0' implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) implementation (name:'../libs/beautysdk-202202241203',ext:'aar') implementation (name:'../libs/svgaplayer-release-v1.2.1',ext:'aar') //socket.io implementation('io.socket:socket.io-client:1.0.0') { exclude group: 'org.json', module: 'json' } //common api project(path: ':common') api project(path:':FaceUnity')//新娱美颜 annotationProcessor rootProject.ext.dependencies["arouter-compiler"] //工具 api rootProject.ext.dependencies["blank-utilcode"] implementation 'com.eightbitlab:blurview:1.6.6' implementation 'com.google.code.gson:gson:2.8.6' implementation "com.getkeepsafe.relinker:relinker:1.4.4" } apply plugin: 'com.android.library' apply plugin: 'img-optimizer' apply plugin: 'kotlin-android' android { compileSdkVersion rootProject.ext.android.compileSdkVersion buildToolsVersion rootProject.ext.android.buildToolsVersion aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false packagingOptions { pickFirst "lib/armeabi/libyuvutils.so" pickFirst "lib/arm64-v8a/libyuvutils.so" pickFirst "lib/armeabi-v7a/libyuvutils.so" pickFirst "lib/armeabi/libyuvtools.so" pickFirst "lib/arm64-v8a/libyuvtools.so" pickFirst "lib/armeabi-v7a/libyuvtools.so" exclude "lib/arm64-v8a/libmmcv_api_handgesture.so" exclude "lib/arm64-v8a/libmmcv_api_express.so" exclude "lib/arm64-v8a/libMediaEncoder.so" exclude "lib/arm64-v8a/libarcore_sdk_c.so" exclude "lib/arm64-v8a/libmediadecoder.so" exclude "lib/arm64-v8a/libMediaMuxer.so" exclude "lib/arm64-v8a/libarcore_sdk_jni.so" exclude "lib/arm64-v8a/libMediaUtils.so" exclude "lib/arm64-v8a/libcosmosffmpeg.so" } defaultConfig { minSdkVersion rootProject.ext.android.minSdkVersion targetSdkVersion rootProject.ext.android.targetSdkVersion versionCode rootProject.ext.android.versionCode versionName rootProject.ext.android.versionName manifestPlaceholders = rootProject.ext.manifestPlaceholders ndk { abiFilters "armeabi-v7a", "arm64-v8a" } javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] } } } aaptOptions { cruncherEnabled = false useNewCruncher = false } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } kotlinOptions { allWarningsAsErrors = true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } repositories { flatDir { dirs 'libs', '../libs' } mavenCentral() } dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.0' implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) implementation (name:'../libs/beautysdk-202202241203',ext:'aar') implementation (name:'../libs/svgaplayer-release-v1.2.1',ext:'aar') //socket.io implementation('io.socket:socket.io-client:1.0.0') { exclude group: 'org.json', module: 'json' } //common api project(path: ':common') api project(path:':FaceUnity')//新娱美颜 annotationProcessor rootProject.ext.dependencies["arouter-compiler"] //工具 api rootProject.ext.dependencies["blank-utilcode"] implementation 'com.eightbitlab:blurview:1.6.6' implementation 'com.google.code.gson:gson:2.8.6' implementation "com.getkeepsafe.relinker:relinker:1.4.4" implementation 'com.google.android.exoplayer:exoplayer-core:2.18.1' implementation 'com.google.android.exoplayer:exoplayer-rtsp:2.17.1' implementation 'com.google.android.exoplayer:exoplayer-ui:2.18.1' }

View File

@ -18,6 +18,10 @@ import android.widget.ImageView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.ui.StyledPlayerView;
import com.lzy.okserver.OkDownload; import com.lzy.okserver.OkDownload;
import com.lzy.okserver.download.DownloadTask; import com.lzy.okserver.download.DownloadTask;
import com.tencent.live2.V2TXLiveDef; import com.tencent.live2.V2TXLiveDef;
@ -78,7 +82,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
private ViewGroup mLeftContainer; private ViewGroup mLeftContainer;
private ViewGroup mRightContainer; private ViewGroup mRightContainer;
private RelativeLayout mPkContainer; private RelativeLayout mPkContainer;
public static TXCloudVideoView mVideoView; public static StyledPlayerView mVideoView;
private View mLoading; private View mLoading;
private ImageView mCover; private ImageView mCover;
@ -90,7 +94,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
private boolean mPausedPlay;//是否被动暂停了播放 private boolean mPausedPlay;//是否被动暂停了播放
public static int landscape; //1h 2s public static int landscape; //1h 2s
public static Context contexts; public static Context contexts;
public V2TXLivePlayer mPlayer; public ExoPlayer mPlayer;
public static FrameLayout ry_view; public static FrameLayout ry_view;
@ -134,7 +138,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
mLeftContainer = (ViewGroup) findViewById(R.id.left_container); mLeftContainer = (ViewGroup) findViewById(R.id.left_container);
mRightContainer = (ViewGroup) findViewById(R.id.right_container); mRightContainer = (ViewGroup) findViewById(R.id.right_container);
mPkContainer = (RelativeLayout) findViewById(R.id.pk_container); mPkContainer = (RelativeLayout) findViewById(R.id.pk_container);
mVideoView = (TXCloudVideoView) findViewById(R.id.video_view); mVideoView = (StyledPlayerView) findViewById(R.id.video_view);
ry_view = (FrameLayout) findViewById(R.id.ry_view); ry_view = (FrameLayout) findViewById(R.id.ry_view);
leave = (ImageView) findViewById(R.id.leave); leave = (ImageView) findViewById(R.id.leave);
mLoading = findViewById(R.id.loading); mLoading = findViewById(R.id.loading);
@ -147,6 +151,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
params.height = vHeight; params.height = vHeight;
mPkContainer.requestLayout(); mPkContainer.requestLayout();
mPlayer = new ExoPlayer.Builder(mContext)
.build();
mVideoView.setPlayer(mPlayer);
} }
@Override @Override
@ -192,109 +200,20 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
return; return;
} }
mPlayer = new V2TXLivePlayerImpl(mContext);
if (TextUtils.isEmpty(url) || mVideoView == null) { if (TextUtils.isEmpty(url) || mVideoView == null) {
return; return;
} }
//mPlayer.setCacheParams(1.0f, 5.0f); //mPlayer.setCacheParams(1.0f, 5.0f);
mPlayer.setObserver(new V2TXLivePlayerObserver() { if(mPlayer.isPlaying()){
String TAG = "播放流"; mPlayer.stop();
mPlayer.release();
@Override }
public void onError(V2TXLivePlayer player, int code, String msg, Bundle extraInfo) {
super.onError(player, code, msg, extraInfo);
Log.i(TAG, "onError: player = " + player + ", code = " + code + ", msg = " + msg + ", extraInfo = " + extraInfo);
}
@Override
public void onWarning(V2TXLivePlayer player, int code, String msg, Bundle extraInfo) {
super.onWarning(player, code, msg, extraInfo);
Log.i(TAG, "onWarning: " + "player = " + player + ", code = " + code + ", msg = " + msg + ", extraInfo = " + extraInfo);
if (code == 2105) {
// mPlayer.resumeVideo();
// mPlayer.resumeAudio();
mPlayer.stopPlay();
mPlayer.startPlay(purl);
}
}
@Override
public void onVideoPlayStatusUpdate(V2TXLivePlayer player, V2TXLiveDef.V2TXLivePlayStatus status, V2TXLiveDef.V2TXLiveStatusChangeReason reason, Bundle extraInfo) {
super.onVideoPlayStatusUpdate(player, status, reason, extraInfo);
//Log.i(TAG, "onVideoPlayStatusUpdate: " + "player = " + player + ", status = " + status + ", reason = " + reason + ", extraInfo = " + extraInfo);
}
@Override
public void onAudioPlayStatusUpdate(V2TXLivePlayer player, V2TXLiveDef.V2TXLivePlayStatus status, V2TXLiveDef.V2TXLiveStatusChangeReason reason, Bundle extraInfo) {
super.onAudioPlayStatusUpdate(player, status, reason, extraInfo);
//Log.i(TAG, "onAudioPlayStatusUpdate: " + "player = " + player + ", status = " + status + ", reason = " + reason + ", extraInfo = " + extraInfo);
}
@Override
public void onPlayoutVolumeUpdate(V2TXLivePlayer player, int volume) {
super.onPlayoutVolumeUpdate(player, volume);
}
@Override
public void onStatisticsUpdate(V2TXLivePlayer player, V2TXLiveDef.V2TXLivePlayerStatistics statistics) {
super.onStatisticsUpdate(player, statistics);
Map<String, DownloadTask> taskMap = OkDownload.getInstance().getTaskMap();
StringBuilder buffer = new StringBuilder();
buffer.append("|");
for (String key : taskMap.keySet()) {
DownloadTask task = taskMap.get(key);
buffer.append(task.progress.fileName).append(":");
int status = task.progress.status;
switch (status) {
case 0:
buffer.append("无状态");
break;
case 1:
buffer.append("等待");
break;
case 2:
buffer.append("下载中:").append(task.progress.fraction);
break;
case 3:
buffer.append("暂停");
break;
case 4:
buffer.append("错误");
break;
case 5:
buffer.append("完成");
break;
}
buffer.append("|");
}
//Log.i(TAG, "onStatisticsUpdate: " + JSON.toJSONString(statistics) + " |当前下载数 : " + OkDownload.getInstance().getTaskMap().size() + buffer);
if (statistics.fps == 0) {
OkDownload.getInstance().pauseAll();
} else {
OkDownload.getInstance().startAll();
}
}
@Override
public void onSnapshotComplete(V2TXLivePlayer player, Bitmap image) {
super.onSnapshotComplete(player, image);
}
@Override
public void onRenderVideoFrame(V2TXLivePlayer player, V2TXLiveDef.V2TXLiveVideoFrame videoFrame) {
super.onRenderVideoFrame(player, videoFrame);
}
@Override
public void onReceiveSeiMessage(V2TXLivePlayer player, int payloadType, byte[] data) {
super.onReceiveSeiMessage(player, payloadType, data);
}
});
mPlayer.setRenderView(mVideoView);
purl = url; purl = url;
mPlayer.startPlay(url); MediaItem item = MediaItem.fromUri(url);
mPlayer.setMediaItem(item);
mPlayer.prepare();
mPlayer.play();
onPrepared(); onPrepared();
} }
@ -305,7 +224,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
mEnd = true; mEnd = true;
mStarted = false; mStarted = false;
if (mPlayer != null) { if (mPlayer != null) {
mPlayer.stopPlay(); mPlayer.stop();
mPlayer.release();
} }
L.e(TAG, "release------->"); L.e(TAG, "release------->");
} }
@ -319,7 +239,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
} }
} }
if (mPlayer != null) { if (mPlayer != null) {
mPlayer.stopPlay(); mPlayer.stop();
mPlayer.release();
} }
stopPlay2(); stopPlay2();
} }
@ -508,7 +429,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
params.height = RelativeLayout.LayoutParams.MATCH_PARENT; params.height = RelativeLayout.LayoutParams.MATCH_PARENT;
params.topMargin = 0; params.topMargin = 0;
params.addRule(RelativeLayout.ALIGN_TOP); params.addRule(RelativeLayout.ALIGN_TOP);
mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation270); // mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation270);
mVideoView.requestLayout(); mVideoView.requestLayout();
} }
@ -518,7 +439,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams();
params.height = vHeight; params.height = vHeight;
params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top);
mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation0); // mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation0);
params.addRule(RelativeLayout.ALIGN_TOP); params.addRule(RelativeLayout.ALIGN_TOP);
mVideoView.requestLayout(); mVideoView.requestLayout();
} }
@ -565,10 +486,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
Log.e("ry", "退出多人房间成功"); Log.e("ry", "退出多人房间成功");
new Handler(Looper.getMainLooper()).post(new Runnable() { new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() { public void run() {
mPlayer.startPlay(purl); mPlayer.setMediaItem(MediaItem.fromUri(purl));
Log.e("ry", mPlayer.isPlaying() + "purl" + purl); Log.e("ry", mPlayer.isPlaying() + "purl" + purl);
if (mPlayer.isPlaying() != 1) { if (!mPlayer.isPlaying()) {
mPlayer.startPlay(purl); mPlayer.prepare();
mPlayer.play();
} }
ry_view.removeAllViews(); ry_view.removeAllViews();
onPrepared(); onPrepared();
@ -630,7 +552,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
for (RCRTCInputStream stream : data.getLiveStreams()) { for (RCRTCInputStream stream : data.getLiveStreams()) {
if (stream.getMediaType() == RCRTCMediaType.VIDEO) { if (stream.getMediaType() == RCRTCMediaType.VIDEO) {
//暂停播放 //暂停播放
mPlayer.stopPlay(); mPlayer.stop();
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示 //如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示
//如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示 //如果远端用户发布的是视频流创建显示视图RCRTCVideoView并添加到布局中显示

View File

@ -8,9 +8,10 @@
> >
<com.tencent.rtmp.ui.TXCloudVideoView <com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/video_view" android:id="@+id/video_view"
android:layout_width="match_parent" android:layout_width="match_parent"
app:use_controller="false"
android:layout_height="match_parent"/> android:layout_height="match_parent"/>
<ImageView <ImageView