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 7ca05a53f..deb8cba68 100644
--- a/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java
+++ b/live/src/main/java/com/yunbao/live/utils/LiveExoPlayerManager.java
@@ -6,12 +6,12 @@ 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.ui.StyledPlayerView;
import com.google.android.exoplayer2.video.VideoSize;
/**
@@ -23,7 +23,7 @@ public class LiveExoPlayerManager {
private final int MODEL_PLAY2 = 1;//当前子播放器
private Context mContext;
private ExoPlayer player1, player2;
- private SurfaceView mainView;//渲染视图
+ private StyledPlayerView mainView;//渲染视图
private int status = MODEL_PLAY1;
private Player.Listener listener;
private boolean isSwitchUrl = false;//是否为主动切换播放器
@@ -42,11 +42,12 @@ public class LiveExoPlayerManager {
setAnalyticsListener();
}
+
public void setListener(Player.Listener listener) {
this.listener = listener;
}
- public void setMainView(SurfaceView mainView) {
+ public void setMainView(StyledPlayerView mainView) {
this.mainView = mainView;
}
@@ -119,7 +120,8 @@ public class LiveExoPlayerManager {
Player.Listener.super.onIsPlayingChanged(isPlaying);
if (isPlaying) {
Log.i(TAG, "onIsPlayingChanged1: 播放了");
- player1.setVideoSurfaceView(mainView);
+ //player1.setVideoSurfaceView(mainView);
+ mainView.setPlayer(player1);
status = MODEL_PLAY1;
isSwitchUrl = false;
if (listener != null) {
@@ -169,7 +171,8 @@ public class LiveExoPlayerManager {
Player.Listener.super.onIsPlayingChanged(isPlaying);
if (isPlaying) {
Log.i(TAG, "onIsPlayingChanged2: 播放了");
- player2.setVideoSurfaceView(mainView);
+ //player2.setVideoSurfaceView(mainView);
+ mainView.setPlayer(player2);
status = MODEL_PLAY2;
isSwitchUrl = false;
if (listener != null) {
@@ -202,7 +205,8 @@ public class LiveExoPlayerManager {
public void startUrl(String url) {
isSwitchUrl = true;
playBufferIndex = 0;
- getNowPlayer().setVideoSurfaceView(mainView);
+ //getNowPlayer().setVideoSurfaceView(mainView);
+ mainView.setPlayer(getNowPlayer());
getNowPlayer().setMediaItem(createMediaItem(url));
getNowPlayer().prepare();
getNowPlayer().play();
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 d3e391dcf..e550e8c64 100644
--- a/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java
+++ b/live/src/main/java/com/yunbao/live/views/LivePlayRyViewHolder.java
@@ -13,7 +13,6 @@ 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;
@@ -22,13 +21,9 @@ import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
-import androidx.annotation.Nullable;
-
-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.ui.StyledPlayerView;
import com.google.android.exoplayer2.video.VideoSize;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
@@ -93,7 +88,7 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
private ViewGroup mLeftContainer;
private ViewGroup mRightContainer;
private RelativeLayout mPkContainer;
- public static SurfaceView mVideoView;
+ public StyledPlayerView mVideoView;
private View mLoading, mLoading2;
private ImageView mCover;
@@ -145,7 +140,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 = (SurfaceView) 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);
@@ -353,8 +348,8 @@ public class LivePlayRyViewHolder extends LiveRoomPlayViewHolder {
public void stopPlay2() {
}
-
- public static void setViewUP(int i) {
+ @Override
+ public void setViewUP(int i) {
if (mVideoView == null) return;
Log.e("收", "整理" + i);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams();
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 420351b89..49f7d01d8 100644
--- a/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java
+++ b/live/src/main/java/com/yunbao/live/views/LiveRoomPlayViewHolder.java
@@ -62,6 +62,8 @@ public abstract class LiveRoomPlayViewHolder extends AbsViewHolder implements IL
this.mLiveBean = data;
}
+ public void setViewUP(int i){}
+
public OnMicCallback getOnMicCallback() {
return onMicCallback;
}
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 a4d8ce394..90bce1437 100644
--- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java
+++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java
@@ -492,17 +492,17 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
}
}
- if (data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")) {
+ if (mLivePlayViewHolder != null && data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")) {
- LivePlayRyViewHolder.setViewUP(1);
+ mLivePlayViewHolder.setViewUP(1);
}
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.pkHandler = false;
}
- if (pkInfo.getIntValue("ifpk") == 1 && pkInfo.getString("end_pk_time").equals("0")) {//pk开始了
+ if (mLivePlayViewHolder != null && pkInfo.getIntValue("ifpk") == 1 && pkInfo.getString("end_pk_time").equals("0")) {//pk开始了
- LivePlayRyViewHolder.setViewUP(2);
+ mLivePlayViewHolder.setViewUP(2);
//pk排名数据
LivePKUserListBean livePKUserListBean = JSON.parseObject(pkInfo.getString("pk_top_users"), LivePKUserListBean.class);
@@ -526,7 +526,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
mLiveRoomViewHolder.pkHandler = true;
mLiveRoomViewHolder.initPkRank(null);
}
- LivePlayRyViewHolder.setViewUP(3);
+ if(mLivePlayViewHolder != null) {
+ mLivePlayViewHolder.setViewUP(3);
+ }
//pk排名数据
LivePKUserListBean livePKUserListBean = JSON.parseObject(pkInfo.getString("pk_top_users"), LivePKUserListBean.class);
@@ -541,7 +543,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
if (mLiveRoomViewHolder != null) {
mLiveRoomViewHolder.initPkRank(null);
}
- LivePlayRyViewHolder.setViewUP(4);
+ if(mLivePlayViewHolder != null) {
+ mLivePlayViewHolder.setViewUP(4);
+ }
mLiveRoomViewHolder.UpPkBar(pkInfo.getJSONArray("userlist"), mLiveBean.getUid(), pkInfo.getIntValue("drpk_time"));
}
@@ -1270,7 +1274,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
mLivePlayViewHolder.setLiveBeanLandscape(1);
}
if (mContext instanceof LiveAudienceActivity) {
- ((LiveAudienceActivity)mContext).setPkStatus(true);
+ ((LiveAudienceActivity) mContext).setPkStatus(true);
}
}
@@ -1287,7 +1291,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
mLivePlayViewHolder.setLiveBeanLandscape(landscape);
}
if (mContext instanceof LiveAudienceActivity) {
- ((LiveAudienceActivity)mContext).setPkStatus(false);
+ ((LiveAudienceActivity) mContext).setPkStatus(false);
}
}
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 6dc70080c..a7b2b1a81 100644
--- a/live/src/main/res/layout/view_live_play_ksy.xml
+++ b/live/src/main/res/layout/view_live_play_ksy.xml
@@ -7,9 +7,12 @@
android:layout_height="match_parent">
-