From 137dbc72d8e4c23a0f3fbdb326fe5ecc6fb316d7 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 28 Dec 2022 17:51:35 +0800 Subject: [PATCH 1/7] update --- config.gradle | 4 +- live/build.gradle | 2 +- .../live/views/LivePlayKsyViewHolder.java | 2 +- .../live/views/LivePlayRyViewHolder.java | 210 ++++++++++++++---- .../live/views/LivePlayTxViewHolder.java | 2 +- .../views/LivePlayTxViewHolder_backup.java | 2 +- .../live/views/LiveRoomPlayViewHolder.java | 9 +- .../yunbao/live/views/LiveRoomViewHolder.java | 7 +- .../live/views/PortraitLiveManager.java | 9 +- .../main/res/layout/view_live_play_ksy.xml | 2 +- 10 files changed, 194 insertions(+), 55 deletions(-) diff --git a/config.gradle b/config.gradle index 6f21be570..ac60b7e57 100644 --- a/config.gradle +++ b/config.gradle @@ -10,9 +10,9 @@ ext { manifestPlaceholders = [ //正式 - serverHost : "https://napi.yaoulive.com", +// serverHost : "https://napi.yaoulive.com", // 測試 -// serverHost : "https://ceshi.yaoulive.com", + serverHost : "https://ceshi.yaoulive.com", //腾讯地图 txMapAppKey : "EOZBZ-ASLCU-4XPV3-BDCHZ-4E3Q7-H4BWB", diff --git a/live/build.gradle b/live/build.gradle index f8dddcdbd..0329c0beb 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" //ExoPlayer,腾讯的播放器不支持无缝切换 implementation 'com.google.android.exoplayer:exoplayer:2.18.2' implementation 'com.google.android.exoplayer:exoplayer-core:2.18.2@aar' } \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java index 374978a99..b50a38d80 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java @@ -128,7 +128,7 @@ public class LivePlayKsyViewHolder extends LiveRoomPlayViewHolder { * @param url 流地址 */ @Override - public void play(String url) { + public void play(String url,int playModel) { mPlayer = new V2TXLivePlayerImpl(mContext); if (TextUtils.isEmpty(url) || mVideoView == null) { 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 8d979b241..00994d59d 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -6,15 +6,14 @@ import static cn.rongcloud.rtc.core.RendererCommon.ScalingType.SCALE_ASPECT_FILL import android.Manifest; import android.app.Dialog; import android.content.Context; -import android.graphics.Bitmap; import android.graphics.Color; import android.media.AudioManager; -import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.text.TextUtils; import android.util.Log; import android.view.Gravity; +import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; @@ -23,19 +22,18 @@ import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; -import com.alibaba.fastjson.JSON; +import androidx.annotation.Nullable; + +import com.google.android.exoplayer2.ExoPlayer; +import com.google.android.exoplayer2.MediaItem; +import com.google.android.exoplayer2.PlaybackException; +import com.google.android.exoplayer2.Player; +import com.google.android.exoplayer2.Timeline; +import com.google.android.exoplayer2.Tracks; +import com.google.android.exoplayer2.video.VideoSize; import com.lzf.easyfloat.EasyFloat; -import com.lzy.okserver.OkDownload; -import com.lzy.okserver.download.DownloadTask; -import com.tencent.live2.V2TXLiveDef; -import com.tencent.live2.V2TXLivePlayer; -import com.tencent.live2.V2TXLivePlayerObserver; -import com.tencent.live2.impl.V2TXLivePlayerImpl; -import com.tencent.rtmp.ui.TXCloudVideoView; -import com.yunbao.common.bean.CrashSaveBean; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; -import com.yunbao.common.utils.DeviceUtils; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.L; @@ -56,7 +54,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; -import java.util.Map; import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.RCRTCRemoteUser; @@ -89,7 +86,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { private ViewGroup mLeftContainer; private ViewGroup mRightContainer; private RelativeLayout mPkContainer; - public static TXCloudVideoView mVideoView; + public static SurfaceView mVideoView; private View mLoading, mLoading2; private ImageView mCover; @@ -101,15 +98,16 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { private boolean mPausedPlay;//是否被动暂停了播放 public int landscape; //1h 2s public static Context contexts; - public V2TXLivePlayer mPlayer; public static FrameLayout ry_view; private static final int VIDEO_VERTICAL = 1; private static final int VIDEO_HORIZONTAL = 2; - int videoLandscape; // 视频方向,1=竖屏,2=横屏 + int videoLandscape = -1; // 视频方向,1=竖屏,2=横屏 static int vHeight;//视频高 private TextView debugView; + private ExoPlayer mPlayer, mPlayer2; + private boolean isPlayer = true; //0未申请1申请中2连麦中 @@ -141,7 +139,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 = (SurfaceView) findViewById(R.id.video_view); ry_view = (FrameLayout) findViewById(R.id.ry_view); leave = (ImageView) findViewById(R.id.leave); mLoading = findViewById(R.id.loading); @@ -154,9 +152,14 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mPkContainer.getLayoutParams(); params.height = vHeight; mPkContainer.requestLayout(); - mPlayer = new V2TXLivePlayerImpl(mContext); - mPlayer.setRenderView(mVideoView); + mPlayer = new ExoPlayer.Builder(mContext) + .build(); + mPlayer2 = new ExoPlayer.Builder(mContext).build(); + mPlayer.setVideoSurfaceView(mVideoView); + mPlayer2.setVideoSurfaceView(mVideoView); + mPlayer.addListener(new ExoPlayerListener(true)); + mPlayer2.addListener(new ExoPlayerListener(false)); debugView = new TextView(mContext); debugView.setBackgroundColor(Color.WHITE); @@ -247,13 +250,12 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { */ @Override public void resumePlay() { - if (mPlayer.isPlaying() != 1) { + if (!mPlayer.isPlaying()) { new Handler(Looper.getMainLooper()) .postDelayed(() -> { - mPlayer.stopPlay(); - int val = mPlayer.startPlay(purl); + mPlayer.stop(); + mPlayer.play(); // ToastUtil.show("强制播放" + val); - Log.i(TAG, "强制播放: " + val); }, 100); } } @@ -264,7 +266,14 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { * @param url 流地址 */ @Override - public void play(String url) { + public void play(String url, int playModel) { + if (playModel != PLAY_MODEL_DEF) { + if (videoLandscape == VIDEO_VERTICAL) { + url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); + } else if (videoLandscape == VIDEO_HORIZONTAL) { + url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); + } + } Log.e("purl121", url); if (TextUtils.isEmpty(url) || mVideoView == null) { @@ -275,16 +284,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { if (TextUtils.isEmpty(url) || mVideoView == null) { return; } - mVideoView.clearLastFrame(true); - 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); - debugView.setText("播放出错code=" + code + " msg=" + msg); - } + /*mPlayer.setObserver(new V2TXLivePlayerObserver() { + + @Override public void onWarning(V2TXLivePlayer player, int code, String msg, Bundle extraInfo) { @@ -388,21 +391,55 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public void onReceiveSeiMessage(V2TXLivePlayer player, int payloadType, byte[] data) { super.onReceiveSeiMessage(player, payloadType, data); } - }); - + });*/ + MediaItem item = createMediaItem(url); + if (mPlayer.isPlaying()) { + ToastUtil.show("set 2"); + mPlayer2.setMediaItem(item); + mPlayer2.setVideoSurfaceView(mVideoView); + mPlayer2.prepare(); + mPlayer2.play(); + } else { + ToastUtil.show("set 1"); + mPlayer.setMediaItem(item); + mPlayer.setVideoSurfaceView(mVideoView); + mPlayer.prepare(); + mPlayer.play(); + } + /* if (mPlayer.isPlaying()) { + MediaSource nextSource = new ProgressiveMediaSource.Factory(new DefaultHttpDataSource.Factory()) + .createMediaSource(createMediaItem(url)); + MediaSource oldSource = new ProgressiveMediaSource.Factory(new DefaultHttpDataSource.Factory()) + .createMediaSource(mPlayer.getCurrentMediaItem()); + ClippingMediaSource clippingMediaSource = new ClippingMediaSource(oldSource, 0, 3000, false, true, true); + ConcatenatingMediaSource source = new ConcatenatingMediaSource(clippingMediaSource, nextSource); + mPlayer.addMediaSource(source); + mPlayer.prepare(); + mPlayer.setPlayWhenReady(true); + } else { + MediaItem item = createMediaItem(url); + mPlayer.setMediaItem(item); + mPlayer.prepare(); + mPlayer.play(); + }*/ purl = url; - int V2TXLiveCode = mPlayer.startPlay(url); onPrepared(); } + private MediaItem createMediaItem(String url) { + MediaItem mediaItem = MediaItem.fromUri(url); + return mediaItem; + } + @Override public void release() { mEnd = true; mStarted = false; if (mPlayer != null) { - mPlayer.stopPlay(); + mPlayer.stop(); + mPlayer.release(); } L.e(TAG, "release------->"); } @@ -416,7 +453,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } } if (mPlayer != null) { - mPlayer.stopPlay(); + mPlayer.stop(); } stopPlay2(); } @@ -629,7 +666,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(); } @@ -639,7 +676,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(); } @@ -703,10 +740,13 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Log.e("ry", "退出多人房间成功"); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { - mPlayer.startPlay(purl); + mPlayer.play(); Log.e("ry", mPlayer.isPlaying() + "purl" + purl); - if (mPlayer.isPlaying() != 1) { - mPlayer.startPlay(purl); + if (!mPlayer.isPlaying()) { + MediaItem item = createMediaItem(purl); + mPlayer.setMediaItem(item); + mPlayer.prepare(); + mPlayer.play(); } ry_view.removeAllViews(); ry_view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; @@ -783,7 +823,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { for (RCRTCInputStream stream : data.getLiveStreams()) { if (stream.getMediaType() == RCRTCMediaType.VIDEO) { //暂停播放 - mPlayer.stopPlay(); + mPlayer.stop(); //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 //如果远端用户发布的是视频流,创建显示视图RCRTCVideoView,并添加到布局中显示 @@ -1020,4 +1060,86 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } }); } + + protected void startPlay() { + if (mPlayer.isPlaying()) { + mPlayer.stop(); + mPlayer2.play(); + } else { + mPlayer2.stop(); + mPlayer.play(); + } + } + + private class ExoPlayerListener implements Player.Listener { + String TAG = "播放流"; + boolean isPlayer1; + + public ExoPlayerListener(boolean isPlayer1) { + this.isPlayer1 = isPlayer1; + } + + @Override + public void onPlaybackStateChanged(int playbackState) { + Player.Listener.super.onPlaybackStateChanged(playbackState); + if (playbackState == Player.STATE_READY) { + if (isPlayer1) { + mPlayer2.stop(); + Log.i(TAG, "onPlaybackStateChanged1: " + mPlayer.getCurrentMediaItem().localConfiguration.uri); + mPlayer.setVideoSurfaceView(mVideoView); + mPlayer.play(); + } else { + mPlayer.stop(); + Log.i(TAG, "onPlaybackStateChanged2: " + mPlayer2.getCurrentMediaItem().localConfiguration.uri); + mPlayer2.setVideoSurfaceView(mVideoView); + mPlayer2.play(); + } + + }else if (playbackState==Player.STATE_IDLE){ + if(!isPlayer1){ + mPlayer.stop(); + mPlayer2.prepare(); + }else{ + /* mPlayer2.stop(); + mPlayer.prepare();*/ + } + } + Log.i(TAG, "onPlaybackStateChanged: " + playbackState + " play = " + isPlayer1 + " p1 = " + mPlayer.isPlaying() + " p2 = " + mPlayer2.isPlaying()); + isPlayer = !isPlayer; + } + + @Override + public void onMediaItemTransition(@Nullable MediaItem mediaItem, int reason) { + Player.Listener.super.onMediaItemTransition(mediaItem, reason); + Log.i(TAG, "onMediaItemTransition: " + reason); + } + + @Override + public void onPlayerError(PlaybackException error) { + Player.Listener.super.onPlayerError(error); + debugView.setText("播放出错code=" + error.errorCode + " msg=" + error.getErrorCodeName()); + } + + @Override + public void onVideoSizeChanged(VideoSize videoSize) { + Player.Listener.super.onVideoSizeChanged(videoSize); + if (videoSize.height > videoSize.width) { + videoLandscape = VIDEO_VERTICAL; + } else { + videoLandscape = VIDEO_HORIZONTAL; + } + } + + @Override + public void onTimelineChanged(Timeline timeline, int reason) { + Player.Listener.super.onTimelineChanged(timeline, reason); + Log.i(TAG, "onTimelineChanged: " + reason); + } + + @Override + public void onTracksChanged(Tracks tracks) { + Player.Listener.super.onTracksChanged(tracks); + Log.i(TAG, "onTracksChanged: " + tracks.getGroups().size()); + } + } } diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java index 9aef30b33..be84ebfa8 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java @@ -257,7 +257,7 @@ public class LivePlayTxViewHolder extends LiveRoomPlayViewHolder implements ITXL * @param url 流地址 */ @Override - public void play(String url) { + public void play(String url,int playModel) { url = "webrtc://5664.liveplay.myqcloud.com/live/5664_harchar1"; mPlayer = new V2TXLivePlayerImpl(mContext); diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java index 2aaa2705e..9548eda7b 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java @@ -251,7 +251,7 @@ public class LivePlayTxViewHolder_backup extends LiveRoomPlayViewHolder implemen * @param url 流地址 */ @Override - public void play(String url) { + public void play(String url,int playModel) { if (TextUtils.isEmpty(url)) { return; } diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java index 32ad18a89..5ea00b74f 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java @@ -13,14 +13,21 @@ import com.yunbao.live.interfaces.ILiveLinkMicViewHolder; public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements ILiveLinkMicViewHolder { protected LiveBean mLiveBean; + public static final int PLAY_MODEL_DEF=-1; + public static final int PLAY_MODEL_480=0; + public static final int PLAY_MODEL_720=1; + public static final int PLAY_MODEL_1080=2; + public static final String[] videoRatioHorizontal = new String[]{"_640_480", "_960_720", "_1920_1080","_180_180"}; + public static final String[] videoRatioVertical = new String[]{"_480_640", "_720_960", "_1080_1920","_180_180"}; + public static final String[] videoFps = new String[]{"_24", "_30"}; OnMicCallback onMicCallback;//连麦回调 public LiveRoomPlayViewHolder(Context context, ViewGroup parentView) { super(context, parentView); } - public abstract void play(String url); + public abstract void play(String url,int playModel); public abstract void stopPlay(); diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 6fa9eaa4a..13075c098 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -837,7 +837,12 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis mLiveUserAdapter.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(UserBean bean, int position) { - showUserDialog(bean.getId()); + if (position < 4) { + ToastUtil.show("切换:" + LiveRoomPlayViewHolder.videoRatioVertical[position]); + PortraitLiveManager.portraitLiveManager.test(position); + } else { + showUserDialog(bean.getId()); + } } }); mUserRecyclerView.setAdapter(mLiveUserAdapter); diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 5fd7b77ae..b36d84d29 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -186,6 +186,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe private int landscape; private String leaveStream = "", leaveGroupId = ""; + public static PortraitLiveManager portraitLiveManager; + public PortraitLiveManager setQuitF(boolean quitF) { isQuitF = quitF; @@ -196,6 +198,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe this.mContext = context; this.mIntent = intent; liveImDeletUtil = new LiveImDeletUtil(); + portraitLiveManager=this; ininView(); } @@ -296,7 +299,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mask.setVisibility(View.VISIBLE); mLivePlayViewHolder.setLiveBean(mLiveBean); mLivePlayViewHolder.setCover(mLiveBean.getAvatar()); - mLivePlayViewHolder.play(mLiveBean.getPull()); + mLivePlayViewHolder.play(mLiveBean.getPull(), LiveRoomPlayViewHolder.PLAY_MODEL_DEF); mLivePlayViewHolder.setOnMicCallback(new LiveRoomPlayViewHolder.OnMicCallback() { @Override public void onMikUpdate() { @@ -326,7 +329,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe }); } - + public void test(int model) { + mLivePlayViewHolder.play(mLiveBean.getPull(), model); + } private Runnable sendFIm = new Runnable() { @Override public void run() { 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 b136c4bc5..6dc70080c 100644 --- a/live/src/main/res/layout/view_live_play_ksy.xml +++ b/live/src/main/res/layout/view_live_play_ksy.xml @@ -7,7 +7,7 @@ android:layout_height="match_parent"> - From 181bb5b4451ae574f50107809ab6d888be93966e Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 29 Dec 2022 11:01:23 +0800 Subject: [PATCH 2/7] =?UTF-8?q?update=20=E6=B8=85=E6=99=B0=E5=BA=A6?= =?UTF-8?q?=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/utils/DialogUitl.java | 8 +- .../live/utils/LiveExoPlayerManager.java | 170 ++++++++++++++++++ .../live/views/LivePlayRyViewHolder.java | 119 +++++------- .../live/views/LiveRoomPlayViewHolder.java | 17 +- 4 files changed, 227 insertions(+), 87 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java diff --git a/common/src/main/java/com/yunbao/common/utils/DialogUitl.java b/common/src/main/java/com/yunbao/common/utils/DialogUitl.java index 9ddea94c3..b53f0258b 100644 --- a/common/src/main/java/com/yunbao/common/utils/DialogUitl.java +++ b/common/src/main/java/com/yunbao/common/utils/DialogUitl.java @@ -494,8 +494,12 @@ public class DialogUitl { } } }; - btnConfirm.setOnClickListener(listener); - btnCancel.setOnClickListener(listener); + if(btnConfirm!=null) { + btnConfirm.setOnClickListener(listener); + } + if(btnCancel!=null) { + btnCancel.setOnClickListener(listener); + } dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { diff --git a/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java b/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java new file mode 100644 index 000000000..2ccc0d15e --- /dev/null +++ b/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java @@ -0,0 +1,170 @@ +package com.yunbao.live.utils; + +import android.content.Context; +import android.util.Log; +import android.view.SurfaceView; + +import com.google.android.exoplayer2.ExoPlayer; +import com.google.android.exoplayer2.MediaItem; +import com.google.android.exoplayer2.Player; +import com.google.android.exoplayer2.video.VideoSize; + +public class LiveExoPlayerManager { + private final int MODEL_PLAY1 = 0; + private final int MODEL_PLAY2 = 1; + private Context mContext; + private ExoPlayer player1, player2; + private SurfaceView mainView; + private int status = MODEL_PLAY1; + private Player.Listener listener; + private boolean isSwitchUrl = false; + private String TAG = "播放"; + + public LiveExoPlayerManager(Context mContext) { + this.mContext = mContext; + player1 = new ExoPlayer.Builder(mContext).build(); + player2 = new ExoPlayer.Builder(mContext).build(); + player1.addListener(new Player.Listener() { + @Override + public void onPlaybackStateChanged(int playbackState) { + Player.Listener.super.onPlaybackStateChanged(playbackState); + Log.i(TAG, "onPlaybackStateChanged 1: " + playbackState); + if (playbackState == Player.STATE_READY) { + player2.stop(); + player2.setVideoSurface(null); + player1.play(); + Log.i(TAG, "切换播放器1"); + } else if (playbackState == Player.STATE_BUFFERING && status == MODEL_PLAY1 && !isSwitchUrl) { + if (listener != null) { + listener.onPlaybackStateChanged(playbackState); + } + } + } + + @Override + public void onIsPlayingChanged(boolean isPlaying) { + Player.Listener.super.onIsPlayingChanged(isPlaying); + if (isPlaying) { + Log.i(TAG, "onIsPlayingChanged1: 播放了"); + player1.setVideoSurfaceView(mainView); + status = MODEL_PLAY1; + isSwitchUrl = false; + if (listener != null) { + listener.onIsPlayingChanged(true); + } + } + } + + @Override + public void onVideoSizeChanged(VideoSize videoSize) { + Player.Listener.super.onVideoSizeChanged(videoSize); + if (listener != null) { + listener.onVideoSizeChanged(videoSize); + } + } + + @Override + public void onIsLoadingChanged(boolean isLoading) { + Player.Listener.super.onIsLoadingChanged(isLoading); + Log.i(TAG, "onIsLoadingChanged: 1 " + isLoading); + } + }); + + player2.addListener(new Player.Listener() { + @Override + public void onPlaybackStateChanged(int playbackState) { + Player.Listener.super.onPlaybackStateChanged(playbackState); + Log.i(TAG, "onPlaybackStateChanged 2: " + playbackState); + if (playbackState == Player.STATE_READY) { + player1.stop(); + player1.setVideoSurface(null); + player2.play(); + Log.i(TAG, "切换播放器2 " + player2.isPlaying()); + } else if (playbackState == Player.STATE_BUFFERING && status == MODEL_PLAY2 && !isSwitchUrl) { + if (listener != null) { + listener.onPlaybackStateChanged(playbackState); + } + } + } + + @Override + public void onIsPlayingChanged(boolean isPlaying) { + Player.Listener.super.onIsPlayingChanged(isPlaying); + if (isPlaying) { + Log.i(TAG, "onIsPlayingChanged2: 播放了"); + player2.setVideoSurfaceView(mainView); + status = MODEL_PLAY2; + isSwitchUrl = false; + if (listener != null) { + listener.onIsPlayingChanged(true); + } + } + } + + @Override + public void onVideoSizeChanged(VideoSize videoSize) { + Player.Listener.super.onVideoSizeChanged(videoSize); + if (listener != null) { + listener.onVideoSizeChanged(videoSize); + } + } + + @Override + public void onIsLoadingChanged(boolean isLoading) { + Player.Listener.super.onIsLoadingChanged(isLoading); + Log.i(TAG, "onIsLoadingChanged: 2 " + isLoading); + } + }); + } + + public void setListener(Player.Listener listener) { + this.listener = listener; + } + + public void setMainView(SurfaceView mainView) { + this.mainView = mainView; + } + + public void startUrl(String url) { + isSwitchUrl = true; + getNowPlayer().setVideoSurfaceView(mainView); + getNowPlayer().setMediaItem(createMediaItem(url)); + getNowPlayer().prepare(); + getNowPlayer().play(); + } + + public void switchUrl(String url) { + isSwitchUrl = true; + getNextPlayer().setMediaItem(createMediaItem(url)); + getNextPlayer().prepare(); + } + + private MediaItem createMediaItem(String url) { + return MediaItem.fromUri(url); + } + + public ExoPlayer getNowPlayer() { + return status == MODEL_PLAY1 ? player1 : player2; + } + + private ExoPlayer getNextPlayer() { + return status == MODEL_PLAY1 ? player2 : player1; + } + + public boolean isPlaying() { + return getNowPlayer().isPlaying(); + } + + public void stop() { + getNowPlayer().stop(); + } + + public void play() { + getNowPlayer().play(); + } + + public void release() { + player1.release(); + player2.release(); + } +} 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 00994d59d..4e2e01176 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -24,7 +24,6 @@ import android.widget.TextView; import androidx.annotation.Nullable; -import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.Player; @@ -44,6 +43,7 @@ import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.utils.LiveExoPlayerManager; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -106,13 +106,11 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { static int vHeight;//视频高 private TextView debugView; - private ExoPlayer mPlayer, mPlayer2; - private boolean isPlayer = true; - + private LiveExoPlayerManager mPlayer; //0未申请1申请中2连麦中 RCRTCRoom rcrtcRoom; - String purl; + String purl, srcUrl; public int getLandscape() { return landscape; @@ -153,13 +151,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { params.height = vHeight; mPkContainer.requestLayout(); - mPlayer = new ExoPlayer.Builder(mContext) - .build(); - mPlayer2 = new ExoPlayer.Builder(mContext).build(); - mPlayer.setVideoSurfaceView(mVideoView); - mPlayer2.setVideoSurfaceView(mVideoView); - mPlayer.addListener(new ExoPlayerListener(true)); - mPlayer2.addListener(new ExoPlayerListener(false)); + mPlayer = new LiveExoPlayerManager(mContext); + mPlayer.setMainView(mVideoView); + mPlayer.setListener(new ExoPlayerListener()); debugView = new TextView(mContext); debugView.setBackgroundColor(Color.WHITE); @@ -267,6 +261,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { */ @Override public void play(String url, int playModel) { + srcUrl = url; + PLAY_MODEL = playModel; if (playModel != PLAY_MODEL_DEF) { if (videoLandscape == VIDEO_VERTICAL) { url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); @@ -395,16 +391,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { MediaItem item = createMediaItem(url); if (mPlayer.isPlaying()) { ToastUtil.show("set 2"); - mPlayer2.setMediaItem(item); - mPlayer2.setVideoSurfaceView(mVideoView); - mPlayer2.prepare(); - mPlayer2.play(); + mPlayer.switchUrl(url); } else { ToastUtil.show("set 1"); - mPlayer.setMediaItem(item); - mPlayer.setVideoSurfaceView(mVideoView); - mPlayer.prepare(); - mPlayer.play(); + mPlayer.startUrl(url); } /* if (mPlayer.isPlaying()) { MediaSource nextSource = new ProgressiveMediaSource.Factory(new DefaultHttpDataSource.Factory()) @@ -743,10 +733,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mPlayer.play(); Log.e("ry", mPlayer.isPlaying() + "purl" + purl); if (!mPlayer.isPlaying()) { - MediaItem item = createMediaItem(purl); - mPlayer.setMediaItem(item); - mPlayer.prepare(); - mPlayer.play(); + mPlayer.switchUrl(purl); } ry_view.removeAllViews(); ry_view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; @@ -1061,58 +1048,31 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { }); } - protected void startPlay() { - if (mPlayer.isPlaying()) { - mPlayer.stop(); - mPlayer2.play(); - } else { - mPlayer2.stop(); - mPlayer.play(); + private void showLoadingDialog() { + if (PLAY_MODEL == PLAY_MODEL_480) return; + + new DialogUitl.Builder(mContext) + .setTitle("網絡提示") + .setContent("系統監測到您的網絡不穩定,對此將清晰度變成了流暢,您可以在側邊菜單中的「清晰度」選擇調回。") + .setView(R.layout.dialog_simple_tip) + .setClickCallback(new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + dialog.dismiss(); + } + }).build().show(); + PLAY_MODEL = PLAY_MODEL_480; + String url = srcUrl; + if (videoLandscape == VIDEO_VERTICAL) { + url = url.replace(".flv", videoRatioVertical[PLAY_MODEL_480] + videoFps[0] + ".flv"); + } else if (videoLandscape == VIDEO_HORIZONTAL) { + url = url.replace(".flv", videoRatioHorizontal[PLAY_MODEL_480] + videoFps[0] + ".flv"); } + mPlayer.switchUrl(url); } private class ExoPlayerListener implements Player.Listener { String TAG = "播放流"; - boolean isPlayer1; - - public ExoPlayerListener(boolean isPlayer1) { - this.isPlayer1 = isPlayer1; - } - - @Override - public void onPlaybackStateChanged(int playbackState) { - Player.Listener.super.onPlaybackStateChanged(playbackState); - if (playbackState == Player.STATE_READY) { - if (isPlayer1) { - mPlayer2.stop(); - Log.i(TAG, "onPlaybackStateChanged1: " + mPlayer.getCurrentMediaItem().localConfiguration.uri); - mPlayer.setVideoSurfaceView(mVideoView); - mPlayer.play(); - } else { - mPlayer.stop(); - Log.i(TAG, "onPlaybackStateChanged2: " + mPlayer2.getCurrentMediaItem().localConfiguration.uri); - mPlayer2.setVideoSurfaceView(mVideoView); - mPlayer2.play(); - } - - }else if (playbackState==Player.STATE_IDLE){ - if(!isPlayer1){ - mPlayer.stop(); - mPlayer2.prepare(); - }else{ - /* mPlayer2.stop(); - mPlayer.prepare();*/ - } - } - Log.i(TAG, "onPlaybackStateChanged: " + playbackState + " play = " + isPlayer1 + " p1 = " + mPlayer.isPlaying() + " p2 = " + mPlayer2.isPlaying()); - isPlayer = !isPlayer; - } - - @Override - public void onMediaItemTransition(@Nullable MediaItem mediaItem, int reason) { - Player.Listener.super.onMediaItemTransition(mediaItem, reason); - Log.i(TAG, "onMediaItemTransition: " + reason); - } @Override public void onPlayerError(PlaybackException error) { @@ -1123,6 +1083,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @Override public void onVideoSizeChanged(VideoSize videoSize) { Player.Listener.super.onVideoSizeChanged(videoSize); + Log.i(TAG, "onVideoSizeChanged: width = " + videoSize.width + " height = " + videoSize.height); if (videoSize.height > videoSize.width) { videoLandscape = VIDEO_VERTICAL; } else { @@ -1131,15 +1092,19 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } @Override - public void onTimelineChanged(Timeline timeline, int reason) { - Player.Listener.super.onTimelineChanged(timeline, reason); - Log.i(TAG, "onTimelineChanged: " + reason); + public void onPlaybackStateChanged(int playbackState) { + Player.Listener.super.onPlaybackStateChanged(playbackState); + if (playbackState == Player.STATE_BUFFERING) { + showLoadingDialog(); + } } @Override - public void onTracksChanged(Tracks tracks) { - Player.Listener.super.onTracksChanged(tracks); - Log.i(TAG, "onTracksChanged: " + tracks.getGroups().size()); + public void onIsPlayingChanged(boolean isPlaying) { + Player.Listener.super.onIsPlayingChanged(isPlaying); + if (isPlaying) { + hideCover(); + } } } } diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java index 5ea00b74f..b9ee9a46c 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java @@ -13,13 +13,14 @@ import com.yunbao.live.interfaces.ILiveLinkMicViewHolder; public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements ILiveLinkMicViewHolder { protected LiveBean mLiveBean; - public static final int PLAY_MODEL_DEF=-1; - public static final int PLAY_MODEL_480=0; - public static final int PLAY_MODEL_720=1; - public static final int PLAY_MODEL_1080=2; + public static final int PLAY_MODEL_DEF = -1; + public static final int PLAY_MODEL_480 = 0; + public static final int PLAY_MODEL_720 = 1; + public static final int PLAY_MODEL_1080 = 2; + public static int PLAY_MODEL = PLAY_MODEL_DEF; - public static final String[] videoRatioHorizontal = new String[]{"_640_480", "_960_720", "_1920_1080","_180_180"}; - public static final String[] videoRatioVertical = new String[]{"_480_640", "_720_960", "_1080_1920","_180_180"}; + public static final String[] videoRatioHorizontal = new String[]{"_640_480", "_1280_720", "_1920_1080", "_180_180"}; + public static final String[] videoRatioVertical = new String[]{"_480_640", "_1280_960", "_1080_1920", "_180_180"}; public static final String[] videoFps = new String[]{"_24", "_30"}; OnMicCallback onMicCallback;//连麦回调 @@ -27,7 +28,7 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL super(context, parentView); } - public abstract void play(String url,int playModel); + public abstract void play(String url, int playModel); public abstract void stopPlay(); @@ -66,7 +67,7 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL } - public interface OnMicCallback{ + public interface OnMicCallback { void onMikUpdate(); } From 5db84c1e61ce5ff6ee0764a3ec592a9d2870f17c Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 29 Dec 2022 13:13:05 +0800 Subject: [PATCH 3/7] =?UTF-8?q?update=20=E6=B8=85=E6=99=B0=E5=BA=A6?= =?UTF-8?q?=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/views/CustomDrawerPopupView.java | 6 +- .../common/views/LiveClarityCustomPopup.java | 18 +++++ .../live/activity/LiveAudienceActivity.java | 2 +- .../yunbao/live/event/LiveAudienceEvent.java | 3 +- .../live/utils/LiveExoPlayerManager.java | 1 + .../live/views/LivePlayRyViewHolder.java | 71 ++++++++++++++++++- .../live/views/LiveRoomPlayViewHolder.java | 2 +- 7 files changed, 96 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java b/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java index ab2199dbd..c5c23580c 100644 --- a/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java +++ b/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java @@ -127,8 +127,10 @@ public class CustomDrawerPopupView extends DrawerPopupView { ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.system_notice), new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { -// dismiss(); - + dismiss(); + if (callBack != null) { + callBack.systemNotice(); + } } diff --git a/common/src/main/java/com/yunbao/common/views/LiveClarityCustomPopup.java b/common/src/main/java/com/yunbao/common/views/LiveClarityCustomPopup.java index 13ec97ca9..edf5ec993 100644 --- a/common/src/main/java/com/yunbao/common/views/LiveClarityCustomPopup.java +++ b/common/src/main/java/com/yunbao/common/views/LiveClarityCustomPopup.java @@ -12,16 +12,28 @@ import com.yunbao.common.R; import com.yunbao.common.views.weight.ViewClicksAntiShake; public class LiveClarityCustomPopup extends BottomPopupView implements View.OnClickListener { + public static final int BAN_720 = 1; + public static final int BAN_1080 = 2; private int selectClarity = 1; private RelativeLayout lineSd, lineHd, lineFhd; private ImageView iconSd, iconHd, iconFhd; + private int banSelect; public int getSelectClarity() { return selectClarity; } + public LiveClarityCustomPopup(@NonNull Context context, int selectClarity, int banSelect) { + super(context); + this.selectClarity = selectClarity; + this.banSelect = banSelect; + } + public LiveClarityCustomPopup(@NonNull Context context, int selectClarity) { super(context); + if (selectClarity == -1) { + selectClarity = 0; + } this.selectClarity = selectClarity; } @@ -75,6 +87,12 @@ public class LiveClarityCustomPopup extends BottomPopupView implements View.OnCl selectClarity(selectClarity); dismiss(); }); + if (banSelect == BAN_720) { + lineFhd.setEnabled(false); + lineHd.setEnabled(false); + } else if (banSelect == BAN_1080) { + lineFhd.setEnabled(false); + } } /** diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 135739ce7..d817ab129 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -864,7 +864,7 @@ public class LiveAudienceActivity extends LiveActivity { public void systemNotice() { Bus.get().post(new LiveAudienceEvent() .setBean(mLiveBean) - .setType(LiveAudienceEvent.LiveAudienceType.NOTICE)); + .setType(LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO)); } @Override diff --git a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java index 8e5daccd3..204abebf2 100644 --- a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java +++ b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java @@ -256,7 +256,8 @@ public class LiveAudienceEvent extends BaseModel { UP_PK_TWO(51, "PK头像信息"), CUSTOM_FULL_SERVICE_NOTIFY(51, "全服通知"), CHANGE_VIEW(52, "更改连胜位置"), - UPDATA_ROBOT(53, "更新机器人消息"); + UPDATA_ROBOT(53, "更新机器人消息"), + LIVE_VIDEO(54, "画质选择"); private int type; private String name; diff --git a/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java b/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java index 2ccc0d15e..9e0bf571b 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java @@ -134,6 +134,7 @@ public class LiveExoPlayerManager { } public void switchUrl(String url) { + Log.i(TAG, "switchUrl: "+url); isSwitchUrl = true; getNextPlayer().setMediaItem(createMediaItem(url)); getNextPlayer().prepare(); 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 4e2e01176..253d33e02 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -30,9 +30,13 @@ import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Tracks; import com.google.android.exoplayer2.video.VideoSize; +import com.lxj.xpopup.XPopup; +import com.lxj.xpopup.core.BasePopupView; +import com.lxj.xpopup.interfaces.XPopupCallback; import com.lzf.easyfloat.EasyFloat; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; +import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.L; @@ -40,9 +44,11 @@ import com.yunbao.common.utils.MicStatusManager; import com.yunbao.common.utils.ScreenDimenUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; +import com.yunbao.common.views.LiveClarityCustomPopup; import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.utils.LiveExoPlayerManager; import org.greenrobot.eventbus.EventBus; @@ -132,6 +138,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @Override public void init() { EventBus.getDefault().register(this); + Bus.getOn(this); mRoot = (ViewGroup) findViewById(R.id.root); mSmallContainer = (ViewGroup) findViewById(R.id.small_container); mLeftContainer = (ViewGroup) findViewById(R.id.left_container); @@ -390,10 +397,10 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { });*/ MediaItem item = createMediaItem(url); if (mPlayer.isPlaying()) { - ToastUtil.show("set 2"); + ToastUtil.show("set 2 画质="+playModel); mPlayer.switchUrl(url); } else { - ToastUtil.show("set 1"); + ToastUtil.show("set 1 画质="+playModel); mPlayer.startUrl(url); } /* if (mPlayer.isPlaying()) { @@ -431,6 +438,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { mPlayer.stop(); mPlayer.release(); } + Bus.getOff(this); + EventBus.getDefault().unregister(this); L.e(TAG, "release------->"); } @@ -782,6 +791,64 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { } } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onOpenDrawer(LiveAudienceEvent event) { + if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO) { + int ban = PLAY_MODEL == PLAY_MODEL_720 ? LiveClarityCustomPopup.BAN_1080 : PLAY_MODEL == PLAY_MODEL_480 ? LiveClarityCustomPopup.BAN_720 : 0; + LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, PLAY_MODEL); + new XPopup.Builder(mContext) + .setPopupCallback(new XPopupCallback() { + @Override + public void onCreated(BasePopupView popupView) { + + } + + @Override + public void beforeShow(BasePopupView popupView) { + + } + + @Override + public void onShow(BasePopupView popupView) { + + } + + @Override + public void onDismiss(BasePopupView popupView) { + int selectClarity = liveClarityCustomPopup.getSelectClarity(); + play(srcUrl, selectClarity); + } + + @Override + public void beforeDismiss(BasePopupView popupView) { + + } + + @Override + public boolean onBackPressed(BasePopupView popupView) { + return false; + } + + @Override + public void onKeyBoardStateChanged(BasePopupView popupView, int height) { + + } + + @Override + public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) { + + } + + @Override + public void onClickOutside(BasePopupView popupView) { + + } + }) + .asCustom(liveClarityCustomPopup) + .show(); + } + } + /** * 把观众转换成主播 */ diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java index b9ee9a46c..ffb150b0b 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java @@ -20,7 +20,7 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL public static int PLAY_MODEL = PLAY_MODEL_DEF; public static final String[] videoRatioHorizontal = new String[]{"_640_480", "_1280_720", "_1920_1080", "_180_180"}; - public static final String[] videoRatioVertical = new String[]{"_480_640", "_1280_960", "_1080_1920", "_180_180"}; + public static final String[] videoRatioVertical = new String[]{"_480_640", "_720_1280", "_1080_1920", "_180_180"}; public static final String[] videoFps = new String[]{"_24", "_30"}; OnMicCallback onMicCallback;//连麦回调 From 956bef4b9030739f8b3b34fa663be2d4b1dd067f Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 29 Dec 2022 15:59:03 +0800 Subject: [PATCH 4/7] =?UTF-8?q?update=20=E6=B8=85=E6=99=B0=E5=BA=A6?= =?UTF-8?q?=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/common/bean/EnterRoomNewModel.java | 10 +++ .../com/yunbao/common/utils/DialogUitl.java | 16 ++++ .../common/views/LiveClarityCustomPopup.java | 24 ++++- .../main/res/layout/dialog_live_clarity.xml | 3 + common/src/main/res/layout/dialog_toast.xml | 18 ++++ .../live/adapter/FreePkRecyclerAdapter.java | 2 +- .../live/utils/LiveExoPlayerManager.java | 84 ++++++++++++++--- .../live/views/LivePlayKsyViewHolder.java | 5 ++ .../live/views/LivePlayRyViewHolder.java | 90 ++++++++++++------- .../live/views/LivePlayTxViewHolder.java | 5 ++ .../views/LivePlayTxViewHolder_backup.java | 5 ++ .../live/views/LiveRoomPlayViewHolder.java | 8 ++ .../live/views/PortraitLiveManager.java | 6 +- 13 files changed, 229 insertions(+), 47 deletions(-) create mode 100644 common/src/main/res/layout/dialog_toast.xml diff --git a/common/src/main/java/com/yunbao/common/bean/EnterRoomNewModel.java b/common/src/main/java/com/yunbao/common/bean/EnterRoomNewModel.java index b8245fe3f..66daf307c 100644 --- a/common/src/main/java/com/yunbao/common/bean/EnterRoomNewModel.java +++ b/common/src/main/java/com/yunbao/common/bean/EnterRoomNewModel.java @@ -28,6 +28,8 @@ public class EnterRoomNewModel extends BaseModel { private String isUseHotCard = "";//是否使用热度卡 @SerializedName("liveRoomActivity") private List liveRoomActivityModels = new ArrayList<>();//活动列表 + @SerializedName("clarityType") + private int clarityType; public List getLiveRoomActivityModels() { return liveRoomActivityModels; @@ -109,4 +111,12 @@ public class EnterRoomNewModel extends BaseModel { this.isUseHotCard = isUseHotCard; return this; } + + public int getClarityType() { + return clarityType; + } + + public void setClarityType(int clarityType) { + this.clarityType = clarityType; + } } diff --git a/common/src/main/java/com/yunbao/common/utils/DialogUitl.java b/common/src/main/java/com/yunbao/common/utils/DialogUitl.java index b53f0258b..d75105daf 100644 --- a/common/src/main/java/com/yunbao/common/utils/DialogUitl.java +++ b/common/src/main/java/com/yunbao/common/utils/DialogUitl.java @@ -4,6 +4,8 @@ import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.os.Handler; +import android.os.Looper; import android.text.InputFilter; import android.text.InputType; import android.text.Spanned; @@ -68,6 +70,20 @@ public class DialogUitl { } return dialog; } + public static void showToast(Context context,String content,long delayMillis){ + Dialog dialog = new Dialog(context, R.style.dialog); + dialog.setContentView(R.layout.dialog_toast); + dialog.setCancelable(false); + dialog.setCanceledOnTouchOutside(false); + if (!TextUtils.isEmpty(content)) { + TextView titleView = (TextView) dialog.findViewById(R.id.text); + if (titleView != null) { + titleView.setText(content); + } + } + dialog.show(); + new Handler(Looper.getMainLooper()).postDelayed(dialog::dismiss,delayMillis); + } public static Dialog loadingDialog(Context context) { diff --git a/common/src/main/java/com/yunbao/common/views/LiveClarityCustomPopup.java b/common/src/main/java/com/yunbao/common/views/LiveClarityCustomPopup.java index edf5ec993..b22df8f9c 100644 --- a/common/src/main/java/com/yunbao/common/views/LiveClarityCustomPopup.java +++ b/common/src/main/java/com/yunbao/common/views/LiveClarityCustomPopup.java @@ -2,13 +2,17 @@ package com.yunbao.common.views; import android.content.Context; import android.view.View; +import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.RelativeLayout; +import android.widget.TextView; import androidx.annotation.NonNull; import com.lxj.xpopup.core.BottomPopupView; import com.yunbao.common.R; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.views.weight.ViewClicksAntiShake; public class LiveClarityCustomPopup extends BottomPopupView implements View.OnClickListener { @@ -17,6 +21,8 @@ public class LiveClarityCustomPopup extends BottomPopupView implements View.OnCl private int selectClarity = 1; private RelativeLayout lineSd, lineHd, lineFhd; private ImageView iconSd, iconHd, iconFhd; + private ImageView titleSDImg, titleHDImg, titleFHDImg; + private TextView titleSDText, titleHDText, titleFHDText; private int banSelect; public int getSelectClarity() { @@ -25,8 +31,12 @@ public class LiveClarityCustomPopup extends BottomPopupView implements View.OnCl public LiveClarityCustomPopup(@NonNull Context context, int selectClarity, int banSelect) { super(context); - this.selectClarity = selectClarity; this.banSelect = banSelect; + if (selectClarity == -1) { + selectClarity = 0; + } + this.selectClarity = selectClarity; + ToastUtil.show("ban "+banSelect); } public LiveClarityCustomPopup(@NonNull Context context, int selectClarity) { @@ -67,6 +77,12 @@ public class LiveClarityCustomPopup extends BottomPopupView implements View.OnCl iconSd = findViewById(R.id.icon_sd); iconHd = findViewById(R.id.icon_hd); iconFhd = findViewById(R.id.icon_fhd); + titleSDImg = findViewById(R.id.sd); + titleHDImg = findViewById(R.id.hd); + titleFHDImg = findViewById(R.id.fhd); + titleSDText = findViewById(R.id.sd_text); + titleHDText = findViewById(R.id.hd_text); + titleFHDText = findViewById(R.id.fhd_text); selectClarity(selectClarity); //流畅 ViewClicksAntiShake.clicksAntiShake(lineSd, () -> { @@ -90,8 +106,14 @@ public class LiveClarityCustomPopup extends BottomPopupView implements View.OnCl if (banSelect == BAN_720) { lineFhd.setEnabled(false); lineHd.setEnabled(false); + titleHDImg.setImageAlpha(40); + titleFHDImg.setImageAlpha(40); + titleHDText.setAlpha(0.2f); + titleFHDText.setAlpha(0.2f); } else if (banSelect == BAN_1080) { lineFhd.setEnabled(false); + titleFHDText.setAlpha(0.2f); + titleFHDImg.setImageAlpha(20); } } diff --git a/common/src/main/res/layout/dialog_live_clarity.xml b/common/src/main/res/layout/dialog_live_clarity.xml index 35fd83425..04d3d5a58 100644 --- a/common/src/main/res/layout/dialog_live_clarity.xml +++ b/common/src/main/res/layout/dialog_live_clarity.xml @@ -41,6 +41,7 @@ android:src="@mipmap/icon_sd" /> + + + + + \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java index 93a0c7762..57b0f377b 100644 --- a/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/FreePkRecyclerAdapter.java @@ -115,7 +115,7 @@ public class FreePkRecyclerAdapter extends RefreshAdapter { } if (freePkNum == 0 && mDrPkNum == -1) { ToastUtil.show(R.string.free_pk_num_null); - return; + // return; } LiveHttpUtil.getMicList(LiveRyAnchorActivity.mLiveUid, 0, new com.yunbao.common.http.HttpCallback() { diff --git a/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java b/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java index 9e0bf571b..e0da52982 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java @@ -1,12 +1,17 @@ package com.yunbao.live.utils; import android.content.Context; +import android.os.Handler; +import android.os.Looper; import android.util.Log; import android.view.SurfaceView; import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.Player; +import com.google.android.exoplayer2.analytics.AnalyticsListener; +import com.google.android.exoplayer2.analytics.PlaybackStats; +import com.google.android.exoplayer2.analytics.PlaybackStatsListener; import com.google.android.exoplayer2.video.VideoSize; public class LiveExoPlayerManager { @@ -19,11 +24,66 @@ public class LiveExoPlayerManager { private Player.Listener listener; private boolean isSwitchUrl = false; private String TAG = "播放"; + private int playBufferIndex = 0; + private Handler handler; public LiveExoPlayerManager(Context mContext) { this.mContext = mContext; player1 = new ExoPlayer.Builder(mContext).build(); player2 = new ExoPlayer.Builder(mContext).build(); + handler = new Handler(Looper.getMainLooper()); + setListener(); + setAnalyticsListener(); + } + + public void setListener(Player.Listener listener) { + this.listener = listener; + } + + public void setMainView(SurfaceView mainView) { + this.mainView = mainView; + } + + private void setAnalyticsListener() { + player1.addAnalyticsListener(new AnalyticsListener() { + @Override + public void onPlaybackStateChanged( + EventTime eventTime, int state) { + Log.d(TAG, "onPlaybackStateChanged(1) called with: eventTime = [" + eventTime + "], state = [" + state + "]"); + } + + @Override + public void onDroppedVideoFrames( + EventTime eventTime, int droppedFrames, long elapsedMs) { + Log.d(TAG, "onDroppedVideoFrames(1) called with: eventTime = [" + eventTime + "], droppedFrames = [" + droppedFrames + "], elapsedMs = [" + elapsedMs + "]"); + } + }); + + player2.addAnalyticsListener(new AnalyticsListener() { + @Override + public void onPlaybackStateChanged( + EventTime eventTime, int state) { + Log.d(TAG, "onPlaybackStateChanged(2) called with: eventTime = [" + eventTime.totalBufferedDurationMs + "], state = [" + state + "]"); + } + + @Override + public void onDroppedVideoFrames( + EventTime eventTime, int droppedFrames, long elapsedMs) { + Log.d(TAG, "onDroppedVideoFrames(2) called with: eventTime = [" + eventTime + "], droppedFrames = [" + droppedFrames + "], elapsedMs = [" + elapsedMs + "]"); + } + }); + + } + + private Runnable buffRunnable = new Runnable() { + @Override + public void run() { + playBufferIndex = 0; + listener.onPlaybackStateChanged(Player.STATE_BUFFERING); + } + }; + + private void setListener() { player1.addListener(new Player.Listener() { @Override public void onPlaybackStateChanged(int playbackState) { @@ -34,9 +94,13 @@ public class LiveExoPlayerManager { player2.setVideoSurface(null); player1.play(); Log.i(TAG, "切换播放器1"); + handler.removeCallbacks(buffRunnable); + playBufferIndex = 0; } else if (playbackState == Player.STATE_BUFFERING && status == MODEL_PLAY1 && !isSwitchUrl) { if (listener != null) { - listener.onPlaybackStateChanged(playbackState); + if (playBufferIndex++ == 0) { + handler.postDelayed(buffRunnable, 1000); + } } } } @@ -80,9 +144,13 @@ public class LiveExoPlayerManager { player1.setVideoSurface(null); player2.play(); Log.i(TAG, "切换播放器2 " + player2.isPlaying()); + handler.removeCallbacks(buffRunnable); + playBufferIndex = 0; } else if (playbackState == Player.STATE_BUFFERING && status == MODEL_PLAY2 && !isSwitchUrl) { if (listener != null) { - listener.onPlaybackStateChanged(playbackState); + if (playBufferIndex++ == 0) { + handler.postDelayed(buffRunnable, 1000); + } } } } @@ -117,16 +185,9 @@ public class LiveExoPlayerManager { }); } - public void setListener(Player.Listener listener) { - this.listener = listener; - } - - public void setMainView(SurfaceView mainView) { - this.mainView = mainView; - } - public void startUrl(String url) { isSwitchUrl = true; + playBufferIndex = 0; getNowPlayer().setVideoSurfaceView(mainView); getNowPlayer().setMediaItem(createMediaItem(url)); getNowPlayer().prepare(); @@ -134,7 +195,8 @@ public class LiveExoPlayerManager { } public void switchUrl(String url) { - Log.i(TAG, "switchUrl: "+url); + Log.i(TAG, "switchUrl: " + url); + playBufferIndex = 0; isSwitchUrl = true; getNextPlayer().setMediaItem(createMediaItem(url)); getNextPlayer().prepare(); diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java index b50a38d80..4dc373b50 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayKsyViewHolder.java @@ -142,6 +142,11 @@ public class LivePlayKsyViewHolder extends LiveRoomPlayViewHolder { } + @Override + public void switchStream(String url, int playModel) { + + } + @Override public void release() { 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 253d33e02..e61d64f3f 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -106,9 +106,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public static Context contexts; public static FrameLayout ry_view; - private static final int VIDEO_VERTICAL = 1; - private static final int VIDEO_HORIZONTAL = 2; - int videoLandscape = -1; // 视频方向,1=竖屏,2=横屏 + private static final int VIDEO_VERTICAL = 2; + private static final int VIDEO_HORIZONTAL = 1; + int videoLandscape = -1; // 视频方向,2=竖屏,1=横屏 static int vHeight;//视频高 private TextView debugView; @@ -197,6 +197,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @Override public synchronized void setLiveBeanLandscape(int landscape) { this.landscape = landscape; + this.videoLandscape = landscape; if (landscape == 2) { Log.i("收到socket--->", "还原9:16"); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams(); @@ -395,40 +396,38 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { super.onReceiveSeiMessage(player, payloadType, data); } });*/ - MediaItem item = createMediaItem(url); if (mPlayer.isPlaying()) { - ToastUtil.show("set 2 画质="+playModel); - mPlayer.switchUrl(url); - } else { - ToastUtil.show("set 1 画质="+playModel); - mPlayer.startUrl(url); + mPlayer.stop(); } - /* if (mPlayer.isPlaying()) { - MediaSource nextSource = new ProgressiveMediaSource.Factory(new DefaultHttpDataSource.Factory()) - .createMediaSource(createMediaItem(url)); - MediaSource oldSource = new ProgressiveMediaSource.Factory(new DefaultHttpDataSource.Factory()) - .createMediaSource(mPlayer.getCurrentMediaItem()); - ClippingMediaSource clippingMediaSource = new ClippingMediaSource(oldSource, 0, 3000, false, true, true); - ConcatenatingMediaSource source = new ConcatenatingMediaSource(clippingMediaSource, nextSource); - mPlayer.addMediaSource(source); - mPlayer.prepare(); - mPlayer.setPlayWhenReady(true); - } else { - MediaItem item = createMediaItem(url); - mPlayer.setMediaItem(item); - mPlayer.prepare(); - mPlayer.play(); - }*/ + mPlayer.startUrl(url); purl = url; onPrepared(); - } - private MediaItem createMediaItem(String url) { - MediaItem mediaItem = MediaItem.fromUri(url); - return mediaItem; - } + @Override + public void switchStream(String url, int playModel) { + srcUrl = url; + PLAY_MODEL = playModel; + if (playModel != PLAY_MODEL_DEF) { + if (videoLandscape == VIDEO_VERTICAL) { + url = url.replace(".flv", videoRatioVertical[playModel] + videoFps[0] + ".flv"); + } else if (videoLandscape == VIDEO_HORIZONTAL) { + url = url.replace(".flv", videoRatioHorizontal[playModel] + videoFps[0] + ".flv"); + } + } + Log.e("purl121", url); + if (TextUtils.isEmpty(url) || mVideoView == null) { + return; + } + + + if (TextUtils.isEmpty(url) || mVideoView == null) { + return; + } + mPlayer.switchUrl(url); + purl = url; + } @Override public void release() { @@ -445,6 +444,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @Override public void stopPlay() { + Log.i(TAG, "stopPlay: "); if (mCover != null) { mCover.setAlpha(1f); if (mCover.getVisibility() != View.VISIBLE) { @@ -794,8 +794,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @Subscribe(threadMode = ThreadMode.MAIN) public void onOpenDrawer(LiveAudienceEvent event) { if (event.getType() == LiveAudienceEvent.LiveAudienceType.LIVE_VIDEO) { - int ban = PLAY_MODEL == PLAY_MODEL_720 ? LiveClarityCustomPopup.BAN_1080 : PLAY_MODEL == PLAY_MODEL_480 ? LiveClarityCustomPopup.BAN_720 : 0; - LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, PLAY_MODEL); + int ban = roomModel.getClarityType() - 1 == PLAY_MODEL_720 ? LiveClarityCustomPopup.BAN_1080 : roomModel.getClarityType() - 1 == PLAY_MODEL_480 ? LiveClarityCustomPopup.BAN_720 : 0; + LiveClarityCustomPopup liveClarityCustomPopup = new LiveClarityCustomPopup(mContext, PLAY_MODEL, ban); new XPopup.Builder(mContext) .setPopupCallback(new XPopupCallback() { @Override @@ -816,7 +816,30 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { @Override public void onDismiss(BasePopupView popupView) { int selectClarity = liveClarityCustomPopup.getSelectClarity(); - play(srcUrl, selectClarity); + if (selectClarity == PLAY_MODEL) return; + if (selectClarity == 2) { + new DialogUitl.Builder(mContext) + .setTitle("超高清提示") + .setContent("在網速不穩定的情況下,選擇超高清將會有可能導致直播間畫面卡頓,是否確認選擇?") + .setConfrimString("堅持選擇") + .setCancelString("返回") + .setClickCallback(new DialogUitl.SimpleCallback() { + @Override + public void onConfirmClick(Dialog dialog, String content) { + switchStream(srcUrl, selectClarity); + dialog.dismiss(); + showToast(); + } + }).build().show(); + } else { + switchStream(srcUrl, selectClarity); + showToast(); + } + } + + private void showToast() { + DialogUitl.showToast(mContext, " 設置成功\n" + + "正在為你轉換中", 3000); } @Override @@ -1151,6 +1174,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public void onVideoSizeChanged(VideoSize videoSize) { Player.Listener.super.onVideoSizeChanged(videoSize); Log.i(TAG, "onVideoSizeChanged: width = " + videoSize.width + " height = " + videoSize.height); + ToastUtil.show("分辨率: width = " + videoSize.width + " height = " + videoSize.height); if (videoSize.height > videoSize.width) { videoLandscape = VIDEO_VERTICAL; } else { diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java index be84ebfa8..5acc92c24 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder.java @@ -318,6 +318,11 @@ public class LivePlayTxViewHolder extends LiveRoomPlayViewHolder implements ITXL L.e(TAG, "play----url--->" + url); } + @Override + public void switchStream(String url, int playModel) { + + } + @Override public void stopPlay() { mChangeToLeft = false; diff --git a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java index 9548eda7b..1227a9324 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayTxViewHolder_backup.java @@ -280,6 +280,11 @@ public class LivePlayTxViewHolder_backup extends LiveRoomPlayViewHolder implemen L.e(TAG, "play----url--->" + url); } + @Override + public void switchStream(String url, int playModel) { + + } + @Override public void stopPlay() { mChangeToLeft = false; diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java index ffb150b0b..aa28c3378 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java @@ -3,6 +3,7 @@ package com.yunbao.live.views; import android.content.Context; import android.view.ViewGroup; +import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.bean.LiveBean; import com.yunbao.common.views.AbsViewHolder; import com.yunbao.live.interfaces.ILiveLinkMicViewHolder; @@ -23,12 +24,14 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL public static final String[] videoRatioVertical = new String[]{"_480_640", "_720_1280", "_1080_1920", "_180_180"}; public static final String[] videoFps = new String[]{"_24", "_30"}; OnMicCallback onMicCallback;//连麦回调 + public EnterRoomNewModel roomModel; public LiveRoomPlayViewHolder(Context context, ViewGroup parentView) { super(context, parentView); } public abstract void play(String url, int playModel); + public abstract void switchStream(String url, int playModel); public abstract void stopPlay(); @@ -66,6 +69,11 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL this.onMicCallback = onMicCallback; } + public void setLiveEnterRoomNewModel(EnterRoomNewModel data) { + data.setClarityType(2); + this.roomModel = data; + } + public interface OnMicCallback { void onMikUpdate(); diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index b36d84d29..f91dcd5db 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -198,7 +198,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe this.mContext = context; this.mIntent = intent; liveImDeletUtil = new LiveImDeletUtil(); - portraitLiveManager=this; + portraitLiveManager = this; ininView(); } @@ -329,9 +329,11 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe }); } + public void test(int model) { mLivePlayViewHolder.play(mLiveBean.getPull(), model); } + private Runnable sendFIm = new Runnable() { @Override public void run() { @@ -357,6 +359,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } landscape = data.getLiveInfo().getLandscape(); mLivePlayViewHolder.setLiveBeanLandscape(landscape); + mLivePlayViewHolder.setLiveEnterRoomNewModel(data); + mLivePlayViewHolder.switchStream(mLiveBean.getPull(), data.getClarityType() - 1); //是否热度卡加成 liveHandler.postDelayed(() -> mLiveRoomViewHolder.getIsHot(data.getIsUseHotCard()), 700); From 660853d5be46bad2160ccacde422f584759a7ad7 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 29 Dec 2022 15:59:32 +0800 Subject: [PATCH 5/7] =?UTF-8?q?update=20=E6=B8=85=E6=99=B0=E5=BA=A6?= =?UTF-8?q?=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yunbao/common/views/LiveClarityCustomPopup.java | 1 - 1 file changed, 1 deletion(-) diff --git a/common/src/main/java/com/yunbao/common/views/LiveClarityCustomPopup.java b/common/src/main/java/com/yunbao/common/views/LiveClarityCustomPopup.java index b22df8f9c..57e701de3 100644 --- a/common/src/main/java/com/yunbao/common/views/LiveClarityCustomPopup.java +++ b/common/src/main/java/com/yunbao/common/views/LiveClarityCustomPopup.java @@ -36,7 +36,6 @@ public class LiveClarityCustomPopup extends BottomPopupView implements View.OnCl selectClarity = 0; } this.selectClarity = selectClarity; - ToastUtil.show("ban "+banSelect); } public LiveClarityCustomPopup(@NonNull Context context, int selectClarity) { From 7555510d9424279294df76b012dc698b92046fc9 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 29 Dec 2022 16:16:08 +0800 Subject: [PATCH 6/7] =?UTF-8?q?update=20=E6=B8=85=E6=99=B0=E5=BA=A6?= =?UTF-8?q?=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/utils/LiveExoPlayerManager.java | 45 ++++++- .../live/views/LivePlayRyViewHolder.java | 112 +----------------- 2 files changed, 43 insertions(+), 114 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java b/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java index e0da52982..ac2d8a8d7 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java @@ -14,17 +14,21 @@ import com.google.android.exoplayer2.analytics.PlaybackStats; import com.google.android.exoplayer2.analytics.PlaybackStatsListener; import com.google.android.exoplayer2.video.VideoSize; +/** + * 直播间播放器管理器 + * 通过预加载子播放器来实现无缝切换分辨率功能 + */ public class LiveExoPlayerManager { - private final int MODEL_PLAY1 = 0; - private final int MODEL_PLAY2 = 1; + private final int MODEL_PLAY1 = 0;//当前主播放器 + private final int MODEL_PLAY2 = 1;//当前子播放器 private Context mContext; private ExoPlayer player1, player2; - private SurfaceView mainView; + private SurfaceView mainView;//渲染视图 private int status = MODEL_PLAY1; private Player.Listener listener; - private boolean isSwitchUrl = false; + private boolean isSwitchUrl = false;//是否为主动切换播放器 private String TAG = "播放"; - private int playBufferIndex = 0; + private int playBufferIndex = 0;//卡顿计数器 private Handler handler; public LiveExoPlayerManager(Context mContext) { @@ -75,6 +79,9 @@ public class LiveExoPlayerManager { } + /** + * 延迟1秒还未恢复播放则认为卡顿了,可以切分辨率了 + */ private Runnable buffRunnable = new Runnable() { @Override public void run() { @@ -185,6 +192,11 @@ public class LiveExoPlayerManager { }); } + /** + * 开始播放 + * + * @param url 地址 + */ public void startUrl(String url) { isSwitchUrl = true; playBufferIndex = 0; @@ -194,6 +206,11 @@ public class LiveExoPlayerManager { getNowPlayer().play(); } + /** + * 无缝切换 + * + * @param url 地址 + */ public void switchUrl(String url) { Log.i(TAG, "switchUrl: " + url); playBufferIndex = 0; @@ -206,26 +223,44 @@ public class LiveExoPlayerManager { return MediaItem.fromUri(url); } + /** + * 获取当前播放器 + */ public ExoPlayer getNowPlayer() { return status == MODEL_PLAY1 ? player1 : player2; } + /** + * 获取下一个播放器。 + */ private ExoPlayer getNextPlayer() { return status == MODEL_PLAY1 ? player2 : player1; } + /** + * 是否正在播放 + */ public boolean isPlaying() { return getNowPlayer().isPlaying(); } + /** + * 停止播放 + */ public void stop() { getNowPlayer().stop(); } + /** + * 开始播放 + */ public void play() { getNowPlayer().play(); } + /** + * 释放播放器 + */ public void release() { player1.release(); player2.release(); 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 e61d64f3f..d3209358a 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -34,6 +34,7 @@ import com.lxj.xpopup.XPopup; import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.interfaces.XPopupCallback; import com.lzf.easyfloat.EasyFloat; +import com.lzy.okserver.OkDownload; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; import com.yunbao.common.utils.Bus; @@ -284,118 +285,9 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { return; } - if (TextUtils.isEmpty(url) || mVideoView == null) { return; } - - /*mPlayer.setObserver(new V2TXLivePlayerObserver() { - - - - @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); - } - debugView.setText("播放警告code=" + code + " msg=" + msg); - } - - @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("|"); - } - hideCover(); - String debugText = "视频码率:" + statistics.videoBitrate + "\n" + - "音频码率:" + statistics.audioBitrate + "\n" + - "FPS:" + statistics.fps + "\n" + - "CPU:" + statistics.appCpu + "\n" + - "剩余内存:" + DeviceUtils.getMemory(mContext) + "\n" + - "分辨率:" + statistics.height + "x" + statistics.width + "\n" + - "播放状态:" + mPlayer.isPlaying() + "\n" + - "运行时间:" + (System.currentTimeMillis() - CrashSaveBean.getInstance().getStartTime()) / 1000 + "\n"; - debugView.setText(debugText); - Log.i(TAG, "onStatisticsUpdate: " + JSON.toJSONString(statistics) + " |当前下载数 : " + OkDownload.getInstance().getTaskMap().size() + buffer); - if (statistics.height > statistics.width) { - videoLandscape = VIDEO_VERTICAL; - } else { - videoLandscape = VIDEO_HORIZONTAL; - } - 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); - } - });*/ if (mPlayer.isPlaying()) { mPlayer.stop(); } @@ -1187,6 +1079,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Player.Listener.super.onPlaybackStateChanged(playbackState); if (playbackState == Player.STATE_BUFFERING) { showLoadingDialog(); + OkDownload.getInstance().pauseAll(); } } @@ -1195,6 +1088,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { Player.Listener.super.onIsPlayingChanged(isPlaying); if (isPlaying) { hideCover(); + OkDownload.getInstance().startAll(); } } } From 0c053a028e9f10e72ee713d6536f8f678ba2255b Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 29 Dec 2022 16:20:39 +0800 Subject: [PATCH 7/7] =?UTF-8?q?update=20=E6=B8=85=E6=99=B0=E5=BA=A6?= =?UTF-8?q?=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/yunbao/live/views/LivePlayRyViewHolder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d3209358a..62d157f9e 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java @@ -1066,7 +1066,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder { public void onVideoSizeChanged(VideoSize videoSize) { Player.Listener.super.onVideoSizeChanged(videoSize); Log.i(TAG, "onVideoSizeChanged: width = " + videoSize.width + " height = " + videoSize.height); - ToastUtil.show("分辨率: width = " + videoSize.width + " height = " + videoSize.height); + // ToastUtil.show("分辨率: width = " + videoSize.width + " height = " + videoSize.height); if (videoSize.height > videoSize.width) { videoLandscape = VIDEO_VERTICAL; } else {