|
@@ -14,12 +14,15 @@ import android.widget.RelativeLayout;
|
|
|
import com.tencent.liteav.demo.superplayer.player.SuperPlayer;
|
|
|
import com.tencent.liteav.demo.superplayer.player.SuperPlayerImpl;
|
|
|
import com.tencent.liteav.demo.superplayer.player.SuperPlayerObserver;
|
|
|
+import com.tencent.liteav.demo.superplayer.ui.player.CastingPlayer;
|
|
|
import com.tencent.liteav.demo.superplayer.ui.player.FullScreenPlayer;
|
|
|
import com.tencent.liteav.demo.superplayer.ui.player.Player;
|
|
|
import com.tencent.liteav.demo.superplayer.ui.player.WindowPlayer;
|
|
|
import com.tencent.liteav.demo.superplayer.util.TimeoutUtil;
|
|
|
import com.tencent.rtmp.ui.TXCloudVideoView;
|
|
|
|
|
|
+import org.fourthline.cling.model.meta.Device;
|
|
|
+
|
|
|
import java.lang.reflect.Constructor;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -27,36 +30,32 @@ import java.util.List;
|
|
|
public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Listener {
|
|
|
private static final String TAG = "SuperPlayerView";
|
|
|
|
|
|
- private Context mContext;
|
|
|
private ViewGroup mRootView; // SuperPlayerView的根view
|
|
|
|
|
|
private TXCloudVideoView mTXCloudVideoView; // 腾讯云视频播放view
|
|
|
private FullScreenPlayer mFullScreenPlayer; // 全屏模式控制view
|
|
|
- private WindowPlayer mWindowPlayer; // 窗口模式控制view
|
|
|
+ private WindowPlayer mWindowPlayer; // 窗口模式控制view
|
|
|
+ private CastingPlayer mCastingPlayer; // 投屏模式控制view
|
|
|
|
|
|
- private ViewGroup.LayoutParams mLayoutParamWindowMode; // 窗口播放时SuperPlayerView的布局参数
|
|
|
- private ViewGroup.LayoutParams mLayoutParamFullScreenMode; // 全屏播放时SuperPlayerView的布局参数
|
|
|
+ private ViewGroup.LayoutParams mLayoutParamWindowMode; // 窗口播放时SuperPlayerView的布局参数
|
|
|
+ private ViewGroup.LayoutParams mLayoutParamFullScreenMode; // 全屏播放时SuperPlayerView的布局参数
|
|
|
|
|
|
private LayoutParams mVodControllerWindowParams; // 窗口controller的布局参数
|
|
|
private LayoutParams mVodControllerFullScreenParams; // 全屏controller的布局参数
|
|
|
|
|
|
- private OnSuperPlayerViewCallback mPlayerViewCallback; // SuperPlayerView回调
|
|
|
+ private OnPlayerViewCallback mPlayerViewCallback; // SuperPlayerView回调
|
|
|
|
|
|
private SuperPlayer mSuperPlayer; // 超级播放器
|
|
|
|
|
|
- private SuperPlayerModel mCurrentSuperPlayerModel; // 当前正在播放的SuperPlayerModel
|
|
|
-
|
|
|
private int mPlayIndex; // 正在播放model的索引
|
|
|
+ private SuperPlayerModel mCurrentSuperPlayerModel; // 当前正在播放的SuperPlayerModel
|
|
|
private List<SuperPlayerModel> mSuperPlayerModelList; // SuperPlayerModel列表
|
|
|
|
|
|
private boolean mIsPlayInit;
|
|
|
private boolean mIsTimeOut;
|
|
|
|
|
|
// 正常窗口模式下裁切的圆角值
|
|
|
- private float topLeftRadius;
|
|
|
- private float topRightRadius;
|
|
|
- private float bottomLeftRadius;
|
|
|
- private float bottomRightRadius;
|
|
|
+ private float topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius;
|
|
|
|
|
|
public SuperPlayerView(Context context) {
|
|
|
this(context, null);
|
|
@@ -68,9 +67,8 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
|
|
|
public SuperPlayerView(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
- mContext = context;
|
|
|
- initView();
|
|
|
- initPlayer();
|
|
|
+ initView(context);
|
|
|
+ initPlayer(context);
|
|
|
initAttrs(context, attrs);
|
|
|
setWillNotDraw(false);
|
|
|
}
|
|
@@ -102,12 +100,13 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
/**
|
|
|
* 初始化view
|
|
|
*/
|
|
|
- private void initView() {
|
|
|
- mRootView = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.superplayer_vod_view, null);
|
|
|
+ private void initView(Context context) {
|
|
|
+ mRootView = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.superplayer_vod_view, null);
|
|
|
|
|
|
- mTXCloudVideoView = (TXCloudVideoView) mRootView.findViewById(R.id.superplayer_cloud_video_view);
|
|
|
- mFullScreenPlayer = (FullScreenPlayer) mRootView.findViewById(R.id.superplayer_controller_large);
|
|
|
- mWindowPlayer = (WindowPlayer) mRootView.findViewById(R.id.superplayer_controller_small);
|
|
|
+ mTXCloudVideoView = mRootView.findViewById(R.id.superplayer_cloud_video_view);
|
|
|
+ mFullScreenPlayer = mRootView.findViewById(R.id.superplayer_controller_large);
|
|
|
+ mWindowPlayer = mRootView.findViewById(R.id.superplayer_controller_small);
|
|
|
+ mCastingPlayer = mRootView.findViewById(R.id.superplayer_controller_cast);
|
|
|
//防止stop中空指针异常
|
|
|
mSuperPlayerModelList = new ArrayList<>();
|
|
|
|
|
@@ -116,41 +115,47 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
|
|
|
mFullScreenPlayer.setCallback(mControllerCallback);
|
|
|
mWindowPlayer.setCallback(mControllerCallback);
|
|
|
+ mCastingPlayer.setCallback(mControllerCallback);
|
|
|
|
|
|
removeAllViews();
|
|
|
mRootView.removeView(mTXCloudVideoView);
|
|
|
+ mRootView.removeView(mCastingPlayer);
|
|
|
mRootView.removeView(mWindowPlayer);
|
|
|
mRootView.removeView(mFullScreenPlayer);
|
|
|
|
|
|
addView(mTXCloudVideoView);
|
|
|
}
|
|
|
|
|
|
- private void initPlayer() {
|
|
|
- mSuperPlayer = new SuperPlayerImpl(mContext, mTXCloudVideoView);
|
|
|
+ private void initPlayer(Context context) {
|
|
|
+ mSuperPlayer = new SuperPlayerImpl(context, mTXCloudVideoView);
|
|
|
mSuperPlayer.setObserver(new PlayerObserver());
|
|
|
|
|
|
if (mSuperPlayer.getPlayerMode() == SuperPlayerDef.PlayerMode.FULLSCREEN) {
|
|
|
addView(mFullScreenPlayer);
|
|
|
+ mCastingPlayer.hide();
|
|
|
mFullScreenPlayer.hide();
|
|
|
} else if (mSuperPlayer.getPlayerMode() == SuperPlayerDef.PlayerMode.WINDOW) {
|
|
|
addView(mWindowPlayer);
|
|
|
mWindowPlayer.hide();
|
|
|
+ mCastingPlayer.hide();
|
|
|
+ } else if (mSuperPlayer.getPlayerMode() == SuperPlayerDef.PlayerMode.CASTING) {
|
|
|
+ addView(mCastingPlayer);
|
|
|
+ mWindowPlayer.hide();
|
|
|
+ mFullScreenPlayer.hide();
|
|
|
}
|
|
|
|
|
|
- post(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- if (mSuperPlayer.getPlayerMode() == SuperPlayerDef.PlayerMode.WINDOW) {
|
|
|
- mLayoutParamWindowMode = getLayoutParams();
|
|
|
- }
|
|
|
- try {
|
|
|
- // 依据上层Parent的LayoutParam类型来实例化一个新的fullscreen模式下的LayoutParam
|
|
|
- Class parentLayoutParamClazz = getLayoutParams().getClass();
|
|
|
- Constructor constructor = parentLayoutParamClazz.getDeclaredConstructor(int.class, int.class);
|
|
|
- mLayoutParamFullScreenMode = (ViewGroup.LayoutParams) constructor.newInstance(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ post(() -> {
|
|
|
+ if (mSuperPlayer.getPlayerMode() == SuperPlayerDef.PlayerMode.WINDOW) {
|
|
|
+ mLayoutParamWindowMode = getLayoutParams();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 依据上层Parent的LayoutParam类型来实例化一个新的fullscreen模式下的LayoutParam
|
|
|
+ Class parentLayoutParamClazz = getLayoutParams().getClass();
|
|
|
+ Constructor constructor = parentLayoutParamClazz.getDeclaredConstructor(int.class, int.class);
|
|
|
+ mLayoutParamFullScreenMode = (ViewGroup.LayoutParams) constructor.newInstance(
|
|
|
+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -248,6 +253,17 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
mSuperPlayer.stop();
|
|
|
}
|
|
|
|
|
|
+ public void startCast(Device device) {
|
|
|
+ switchPlayMode(SuperPlayerDef.PlayerMode.CASTING);
|
|
|
+ mSuperPlayer.startCast(device);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void stopCast() {
|
|
|
+ mIsPlayInit = false;
|
|
|
+ mSuperPlayer.stopCast();
|
|
|
+ switchPlayMode(SuperPlayerDef.PlayerMode.WINDOW);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onTimeout(boolean timeout) {
|
|
|
this.mIsTimeOut = timeout;
|
|
@@ -267,7 +283,7 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
*
|
|
|
* @param callback
|
|
|
*/
|
|
|
- public void setPlayerViewCallback(OnSuperPlayerViewCallback callback) {
|
|
|
+ public void setPlayerViewCallback(OnPlayerViewCallback callback) {
|
|
|
mPlayerViewCallback = callback;
|
|
|
}
|
|
|
|
|
@@ -278,13 +294,20 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
}
|
|
|
|
|
|
private void handleSwitchPlayMode(SuperPlayerDef.PlayerMode playerMode) {
|
|
|
+ if (playerMode == getPlayerMode()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
mFullScreenPlayer.hide();
|
|
|
mWindowPlayer.hide();
|
|
|
- //请求全屏模式
|
|
|
+ mCastingPlayer.hide();
|
|
|
+
|
|
|
if (playerMode == SuperPlayerDef.PlayerMode.FULLSCREEN) {
|
|
|
onSwitchFullMode(playerMode);
|
|
|
- } else if (playerMode == SuperPlayerDef.PlayerMode.WINDOW) { // 请求窗口模式
|
|
|
+ } else if (playerMode == SuperPlayerDef.PlayerMode.WINDOW) {
|
|
|
onSwitchWindowMode(playerMode);
|
|
|
+ } else if (playerMode == SuperPlayerDef.PlayerMode.CASTING) {
|
|
|
+ onSwitchCastingMode(playerMode);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -294,6 +317,7 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
}
|
|
|
|
|
|
removeView(mWindowPlayer);
|
|
|
+ removeView(mCastingPlayer);
|
|
|
addView(mFullScreenPlayer, mVodControllerFullScreenParams);
|
|
|
setLayoutParams(mLayoutParamFullScreenMode);
|
|
|
if (mPlayerViewCallback != null) {
|
|
@@ -309,6 +333,7 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
}
|
|
|
|
|
|
removeView(mFullScreenPlayer);
|
|
|
+ removeView(mCastingPlayer);
|
|
|
addView(mWindowPlayer, mVodControllerWindowParams);
|
|
|
setLayoutParams(mLayoutParamWindowMode);
|
|
|
if (mPlayerViewCallback != null) {
|
|
@@ -318,6 +343,22 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
mSuperPlayer.switchPlayMode(playerMode);
|
|
|
}
|
|
|
|
|
|
+ private void onSwitchCastingMode(SuperPlayerDef.PlayerMode playerMode) {
|
|
|
+ if (mLayoutParamWindowMode == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ removeView(mWindowPlayer);
|
|
|
+ removeView(mFullScreenPlayer);
|
|
|
+ addView(mCastingPlayer, mVodControllerWindowParams);
|
|
|
+ setLayoutParams(mLayoutParamWindowMode);
|
|
|
+ if (mPlayerViewCallback != null) {
|
|
|
+ mPlayerViewCallback.onStopFullScreenPlay();
|
|
|
+ }
|
|
|
+
|
|
|
+ mSuperPlayer.switchPlayMode(playerMode);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 初始化controller回调
|
|
|
*/
|
|
@@ -367,6 +408,11 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
playNextVideo();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void stopCast() {
|
|
|
+ SuperPlayerView.this.stopCast();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<SuperPlayerModel> getPlayList() {
|
|
|
if (null == mSuperPlayerModelList || mSuperPlayerModelList.isEmpty()) {
|
|
@@ -402,7 +448,7 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
/**
|
|
|
* SuperPlayerView的回调接口
|
|
|
*/
|
|
|
- public interface OnSuperPlayerViewCallback {
|
|
|
+ public interface OnPlayerViewCallback {
|
|
|
|
|
|
/**
|
|
|
* 开始全屏播放
|
|
@@ -414,11 +460,6 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
*/
|
|
|
void onStopFullScreenPlay();
|
|
|
|
|
|
- /**
|
|
|
- * 开始播放回调
|
|
|
- */
|
|
|
- void onPlaying();
|
|
|
-
|
|
|
/**
|
|
|
* 播放下一个视频------
|
|
|
*/
|
|
@@ -429,26 +470,10 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
*/
|
|
|
void onPlayPrepare(int index, SuperPlayerModel model);
|
|
|
|
|
|
- /**
|
|
|
- * 播放结束
|
|
|
- */
|
|
|
- void onPlayEnd();
|
|
|
-
|
|
|
- /**
|
|
|
- * 当播放失败的时候回调
|
|
|
- *
|
|
|
- * @param code
|
|
|
- */
|
|
|
- void onError(int code);
|
|
|
-
|
|
|
/**
|
|
|
* 弹出验证框
|
|
|
*/
|
|
|
void onVerify(SuperPlayerDef.VerifyReason reason);
|
|
|
-
|
|
|
- void onResumePlay();
|
|
|
-
|
|
|
- void onPausePlay();
|
|
|
}
|
|
|
|
|
|
public void release() {
|
|
@@ -458,6 +483,9 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
if (mFullScreenPlayer != null) {
|
|
|
mFullScreenPlayer.release();
|
|
|
}
|
|
|
+ if (mCastingPlayer != null) {
|
|
|
+ mCastingPlayer.release();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -479,11 +507,6 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
return mSuperPlayer.getPlayerState();
|
|
|
}
|
|
|
|
|
|
- private void actonOfPreloadOnPlayPrepare() {
|
|
|
- mWindowPlayer.prepareLoading();
|
|
|
- mFullScreenPlayer.prepareLoading();
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
class PlayerObserver extends SuperPlayerObserver {
|
|
|
|
|
@@ -491,7 +514,7 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
public void onPlayPrepare() {
|
|
|
mWindowPlayer.updatePlayState(SuperPlayerDef.PlayerState.INIT);
|
|
|
mFullScreenPlayer.updatePlayState(SuperPlayerDef.PlayerState.INIT);
|
|
|
- actonOfPreloadOnPlayPrepare();
|
|
|
+ mCastingPlayer.updatePlayState(SuperPlayerDef.PlayerState.INIT);
|
|
|
|
|
|
mWindowPlayer.showBackground();
|
|
|
mFullScreenPlayer.showBackground();
|
|
@@ -501,19 +524,17 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
public void onPlayBegin(String name) {
|
|
|
mWindowPlayer.updatePlayState(SuperPlayerDef.PlayerState.PLAYING);
|
|
|
mFullScreenPlayer.updatePlayState(SuperPlayerDef.PlayerState.PLAYING);
|
|
|
-
|
|
|
- mPlayerViewCallback.onResumePlay();
|
|
|
+ mCastingPlayer.updatePlayState(SuperPlayerDef.PlayerState.PLAYING);
|
|
|
|
|
|
mWindowPlayer.hideBackground();
|
|
|
mFullScreenPlayer.hideBackground();
|
|
|
- notifyCallbackPlaying();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onPlayPause() {
|
|
|
- mPlayerViewCallback.onPausePlay();
|
|
|
mWindowPlayer.updatePlayState(SuperPlayerDef.PlayerState.PAUSE);
|
|
|
mFullScreenPlayer.updatePlayState(SuperPlayerDef.PlayerState.PAUSE);
|
|
|
+ mCastingPlayer.updatePlayState(SuperPlayerDef.PlayerState.PAUSE);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -521,20 +542,20 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
if (mIsPlayInit) {
|
|
|
playNextVideo();
|
|
|
}
|
|
|
-
|
|
|
- notifyCallbackPlayEnd();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onPlayLoading() {
|
|
|
mWindowPlayer.updatePlayState(SuperPlayerDef.PlayerState.LOADING);
|
|
|
mFullScreenPlayer.updatePlayState(SuperPlayerDef.PlayerState.LOADING);
|
|
|
+ mCastingPlayer.updatePlayState(SuperPlayerDef.PlayerState.LOADING);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onPlayProgress(long current, long duration) {
|
|
|
mWindowPlayer.updateVideoProgress(current, duration);
|
|
|
mFullScreenPlayer.updateVideoProgress(current, duration);
|
|
|
+ mCastingPlayer.updateVideoProgress(current, duration);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -544,7 +565,6 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
|
|
|
@Override
|
|
|
public void onError(int code, String message) {
|
|
|
- notifyCallbackPlayError(code);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -555,33 +575,6 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 通知播放开始,降低圈复杂度,单独提取成一个方法
|
|
|
- */
|
|
|
- private void notifyCallbackPlaying() {
|
|
|
- if (mPlayerViewCallback != null) {
|
|
|
- mPlayerViewCallback.onPlaying();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 通知播放结束,降低圈复杂度,单独提取成一个方法
|
|
|
- */
|
|
|
- private void notifyCallbackPlayEnd() {
|
|
|
- if (mPlayerViewCallback != null) {
|
|
|
- mPlayerViewCallback.onPlayEnd();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 通知播放错误,降低圈复杂度,单独提取成一个方法
|
|
|
- */
|
|
|
- private void notifyCallbackPlayError(int code) {
|
|
|
- if (mPlayerViewCallback != null) {
|
|
|
- mPlayerViewCallback.onError(code);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public void setNeedToPause(boolean value) {
|
|
|
mSuperPlayer.setNeedToPause(value);
|
|
|
}
|
|
@@ -590,10 +583,6 @@ public class SuperPlayerView extends RelativeLayout implements TimeoutUtil.Liste
|
|
|
mSuperPlayer.setStartTime((float) startTime);
|
|
|
}
|
|
|
|
|
|
- public void setLoop(boolean b) {
|
|
|
- mSuperPlayer.setLoop(b);
|
|
|
- }
|
|
|
-
|
|
|
/* */
|
|
|
/*----------------正常窗口播放时裁切圆角----------------*/
|
|
|
@Override
|