From f856188a689b32657885fda688a30e12734223bc Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Mon, 31 Oct 2022 15:48:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E4=B8=BAEXOPlayer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- live/build.gradle | 2 +- .../live/views/LivePlayRyViewHolder.java | 138 ++++-------------- .../main/res/layout/view_live_play_ksy.xml | 3 +- 3 files changed, 33 insertions(+), 110 deletions(-) diff --git a/live/build.gradle b/live/build.gradle index f8dddcdbd..e76f37fc2 100644 --- a/live/build.gradle +++ b/live/build.gradle @@ -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" } \ No newline at end of file +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' } \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java index 59a3cb96c..3d934d59f 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -18,6 +18,10 @@ import android.widget.ImageView; import android.widget.RelativeLayout; 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.download.DownloadTask; import com.tencent.live2.V2TXLiveDef; @@ -78,7 +82,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { private ViewGroup mLeftContainer; private ViewGroup mRightContainer; private RelativeLayout mPkContainer; - public static TXCloudVideoView mVideoView; + public static StyledPlayerView mVideoView; private View mLoading; private ImageView mCover; @@ -90,7 +94,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { private boolean mPausedPlay;//是否被动暂停了播放 public static int landscape; //1h 2s public static Context contexts; - public V2TXLivePlayer mPlayer; + public ExoPlayer mPlayer; public static FrameLayout ry_view; @@ -134,7 +138,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mLeftContainer = (ViewGroup) findViewById(R.id.left_container); mRightContainer = (ViewGroup) findViewById(R.id.right_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); leave = (ImageView) findViewById(R.id.leave); mLoading = findViewById(R.id.loading); @@ -147,6 +151,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params.height = vHeight; mPkContainer.requestLayout(); + mPlayer = new ExoPlayer.Builder(mContext) + .build(); + mVideoView.setPlayer(mPlayer); + } @Override @@ -192,109 +200,20 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { return; } - mPlayer = new V2TXLivePlayerImpl(mContext); if (TextUtils.isEmpty(url) || mVideoView == null) { return; } //mPlayer.setCacheParams(1.0f, 5.0f); - mPlayer.setObserver(new V2TXLivePlayerObserver() { - String TAG = "播放流"; - - @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 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); + if(mPlayer.isPlaying()){ + mPlayer.stop(); + mPlayer.release(); + } purl = url; - mPlayer.startPlay(url); + MediaItem item = MediaItem.fromUri(url); + mPlayer.setMediaItem(item); + mPlayer.prepare(); + mPlayer.play(); onPrepared(); } @@ -305,7 +224,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mEnd = true; mStarted = false; if (mPlayer != null) { - mPlayer.stopPlay(); + mPlayer.stop(); + mPlayer.release(); } L.e(TAG, "release------->"); } @@ -319,7 +239,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } } if (mPlayer != null) { - mPlayer.stopPlay(); + mPlayer.stop(); + mPlayer.release(); } stopPlay2(); } @@ -508,7 +429,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params.height = RelativeLayout.LayoutParams.MATCH_PARENT; params.topMargin = 0; params.addRule(RelativeLayout.ALIGN_TOP); - mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation270); + // mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation270); mVideoView.requestLayout(); } @@ -518,7 +439,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); params.height = vHeight; params.topMargin = mContext.getResources().getDimensionPixelOffset(R.dimen.live_top); - mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation0); + // mPlayer.setRenderRotation(V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation0); params.addRule(RelativeLayout.ALIGN_TOP); mVideoView.requestLayout(); } @@ -565,10 +486,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Log.e("ry", "退出多人房间成功"); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { - mPlayer.startPlay(purl); + mPlayer.setMediaItem(MediaItem.fromUri(purl)); Log.e("ry", mPlayer.isPlaying() + "purl" + purl); - if (mPlayer.isPlaying() != 1) { - mPlayer.startPlay(purl); + if (!mPlayer.isPlaying()) { + mPlayer.prepare(); + mPlayer.play(); } ry_view.removeAllViews(); onPrepared(); @@ -630,7 +552,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { for (RCRTCInputStream stream : data.getLiveStreams()) { if (stream.getMediaType() == RCRTCMediaType.VIDEO) { //暂停播放 - mPlayer.stopPlay(); + mPlayer.stop(); //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 diff --git a/live/src/main/res/layout/view_live_play_ksy.xml b/live/src/main/res/layout/view_live_play_ksy.xml index a9d4c4e45..8302e9bfd 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -8,9 +8,10 @@ > -