1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386 |
- package com.daya.tclive.ui;
- import android.Manifest;
- import android.animation.ObjectAnimator;
- import android.annotation.SuppressLint;
- import android.content.ComponentName;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.ServiceConnection;
- import android.content.pm.ActivityInfo;
- import android.content.res.Configuration;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.net.Uri;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.IBinder;
- import android.os.Looper;
- import android.provider.Settings;
- import android.text.TextUtils;
- import android.util.Log;
- import android.view.View;
- import android.view.WindowManager;
- import android.widget.FrameLayout;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.airbnb.lottie.LottieAnimationView;
- import com.alibaba.android.arouter.facade.annotation.Route;
- import com.alibaba.android.arouter.launcher.ARouter;
- import com.bumptech.glide.Glide;
- import com.cooleshow.base.common.WebConstants;
- import com.cooleshow.base.router.RouterPath;
- import com.cooleshow.base.ui.activity.BaseMVPActivity;
- import com.cooleshow.base.utils.AppUtils;
- import com.cooleshow.base.utils.GsonUtils;
- import com.cooleshow.base.utils.LOG;
- import com.cooleshow.base.utils.PermissionUtils;
- import com.cooleshow.base.utils.SoftKeyboardUtil;
- import com.cooleshow.base.utils.ToastUtil;
- import com.cooleshow.base.utils.UiUtils;
- import com.cooleshow.base.widgets.DensityUtil;
- import com.cooleshow.base.widgets.DialogUtil;
- import com.cooleshow.base.widgets.InputBar;
- import com.cooleshow.base.widgets.dialog.CommonConfirmDialog;
- import com.cooleshow.base.widgets.dialog.InputBarDialog;
- import com.cooleshow.usercenter.helper.UserHelper;
- import com.daya.tclive.R;
- import com.daya.tclive.adapter.TTMessageAdapter;
- import com.daya.tclive.bean.FriendInfoBean;
- import com.daya.tclive.bean.LiveRoomInfoBean;
- import com.daya.tclive.bean.LiveStatusSEMIMsg;
- import com.daya.tclive.bean.SendUserInfo;
- import com.daya.tclive.bean.TTMessage;
- import com.daya.tclive.bean.TTUserInfo;
- import com.daya.tclive.constants.ARouterConstace;
- import com.daya.tclive.constants.LiveRoomMsgConstants;
- import com.daya.tclive.constants.TTLiveConfig;
- import com.daya.tclive.contract.TTLiveRoomContract;
- import com.daya.tclive.databinding.AcTtLiveroomLayoutBinding;
- import com.daya.tclive.helper.LiveMemberHelper;
- import com.daya.tclive.helper.LiveMessageHelper;
- import com.daya.tclive.helper.LiveRoomAddLikeHelper;
- import com.daya.tclive.helper.LiveRoomAnimatorHelper;
- import com.daya.tclive.helper.TTLiveHelper;
- import com.daya.tclive.manager.TCIMSdkManager;
- import com.daya.tclive.manager.TRTCSdkManager;
- import com.daya.tclive.message.TCKickOutUserMessage;
- import com.daya.tclive.message.TCLiveForceKickMessage;
- import com.daya.tclive.message.TCSyncAddLikeMessage;
- import com.daya.tclive.message.TCUserEnterMessage;
- import com.daya.tclive.message.TCUserLogOutUnNormalMessage;
- import com.daya.tclive.message.TCUserSeatApplyMessage;
- import com.daya.tclive.message.TCUserSeatResponseMessage;
- import com.daya.tclive.message.TCUserSnappingUpMessage;
- import com.daya.tclive.presenter.TTLiveRoomPresenter;
- import com.daya.tclive.ui.floatPop.FloatWindowHelper;
- import com.daya.tclive.ui.floatPop.FloatingWindowService;
- import com.daya.tclive.widget.TTLiveRoomMicIconView;
- import com.daya.tclive.widget.dialog.LiveRoomCloseMicTipDialog;
- import com.daya.tclive.widget.dialog.LiveRoomClosePageOnMicTipDialog;
- import com.daya.tclive.widget.dialog.LiveRoomExitTipDialog2;
- import com.daya.tclive.widget.dialog.LiveRoomInviteSeatMicTipDialog;
- import com.daya.tclive.widget.dialog.LiveRoomMicManagerDialog;
- import com.daya.tclive.widget.dialog.LiveRoomShopCarDialog;
- import com.daya.tclive.widget.dialog.OpenOverlayPermissionTipDialog;
- import com.gyf.immersionbar.ImmersionBar;
- import com.tbruyelle.rxpermissions3.RxPermissions;
- import com.tencent.imsdk.v2.V2TIMManager;
- import com.tencent.imsdk.v2.V2TIMSDKListener;
- import com.tencent.imsdk.v2.V2TIMUserFullInfo;
- import com.tencent.imsdk.v2.V2TIMUserStatus;
- 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.tencent.trtc.TRTCStatistics;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Locale;
- import java.util.Map;
- import androidx.annotation.NonNull;
- import androidx.constraintlayout.widget.ConstraintLayout;
- import androidx.constraintlayout.widget.ConstraintSet;
- import androidx.constraintlayout.widget.Group;
- import androidx.recyclerview.widget.LinearLayoutManager;
- import androidx.recyclerview.widget.RecyclerView;
- import static com.tencent.live2.V2TXLiveDef.V2TXLiveRotation.V2TXLiveRotation0;
- /**
- * Author by pq, Date on 2023/2/22.
- */
- @Route(path = ARouterConstace.ACTIVITY_TT_LIVE_ROOM)
- public class TCStudentLiveRoomActivity extends BaseMVPActivity<AcTtLiveroomLayoutBinding, TTLiveRoomPresenter> implements TTLiveRoomContract.View, View.OnClickListener, SoftKeyboardUtil.OnSoftInputChangedListener {
- public static final String TAG = "TTLiveRoomActivity";
- ConstraintLayout content_view;
- TXCloudVideoView mVideoView;
- FrameLayout flVideoContainer;
- ConstraintLayout csVideoContainer;
- Group mGroupViews;
- FrameLayout mFlJoinBarrage;
- ImageView mIvClose;
- FrameLayout mFlSnapUpBarrage;
- ImageView mIvSwitchVideoOrientation;
- ImageView mIvSwitchVideoOrientationFull;
- ConstraintLayout cs_header_info;
- FrameLayout msgContainer;
- TextView tv_input;
- FrameLayout fl_input;
- RecyclerView mRecyclerMsg;
- ConstraintLayout mViewLiveStatus;
- ConstraintLayout viewLiveCameraStatus;
- ImageView mIvLiveStatusCameraCenterIcon;
- TextView mTvLiveCameraStatusTipText;
- ImageView mIvLiveStatusCenterIcon;
- TextView mTvLiveStatusTipText;
- TextView mTvJoinBarrage;
- TextView mTvSnapUpBarrage;
- TextView mTvAddLikeCount;
- TextView mTvNumPeople;
- ImageView iv_mic;
- LottieAnimationView mViewShopCarAnim;
- ImageView mIvShopCar;
- ImageView mIvAvatar;
- TextView mTvRoomCreateName;
- ImageView mIvVoiceSwitch;
- Group group_tip;
- Group group_loading;
- TextView tv_retry;
- TextView tv_loading;
- TTLiveRoomMicIconView mLlMicContainer;
- TXCloudVideoView subVideoView;
- private ServiceConnection serviceConnection;
- public static final int SEND_SHOW_FLOAT_WINDOW_TIME = 1000;//退到后台以后检查是否显示悬浮窗等待时长
- public static final int SEND_APP_BACKGROUND_MSG = 1001;//退到后台消息
- public static final int SEND_JUMP_OTHER_PAGE_MSG = 1002;//页面切换消息(购物车详情页等等)
- public static final int OPEN_SHOP_CAR_DIALOG = 1003;//打开购物车
- public static final int LIVE_STATUS_IS_REST = 1;//休息一下,马上回来
- public static final int LIVE_STATUS_IS_CLOSE_VIDEO = 2;//主持人关闭画面
- public static final int LIVE_STATUS_IS_OFFLINE = 3;//直播已结束
- public static final int LIVE_STATUS_LOADING = 4;//直播加载中
- public static final int LIVE_STATUS_ERROR = 5;//直播加载中出错
- private static final String ROOMID_KEY = "roomid_key";
- private static final String SUBJECT_ID_KEY = "subject_id_key";
- private String mRoomId = "";
- private String mUserId = "";
- private ObjectAnimator hideHeaderInfoAnim;
- private ObjectAnimator showHeaderInfoAnim;
- private boolean isEnableChat = false;//默认不禁止
- private boolean isEnableMic = false;//默认不禁止
- private boolean isEnableAll = false;//默认不禁止 黑名单状态
- private boolean isPcClientLive = true;//默认为PC端直播
- private boolean isMuteAllMic = false;//默认为不禁止麦克风
- private boolean isNeedRefresh = false;//是否需要重新刷新房间信息
- private boolean liveIsFinish = false;//直播间是否已结束
- private boolean liveIsPause = false;//直播间是否已暂停
- private long currentAddLikeCount = 0;//当前点赞数量
- private int currentSeatStatus = LiveRoomMsgConstants.MIC_STATUS_NORMAL;//1未连麦,2连麦中,3连麦成功
- private LiveRoomInfoBean roomInfo;
- private InputBarDialog mInputBarDialog;
- private LiveRoomMicManagerDialog mMicManagerDialog;
- private LiveRoomInviteSeatMicTipDialog mInviteSeatMicTipDialog;
- private LiveRoomShopCarDialog mShopCarDialog;
- private V2TXLivePlayer mMLivePlayer;
- private boolean isMuteAll = false;//是否静音
- private boolean isConnectImFailed = false;//IM状态是否异常
- private boolean isOnResume = true;
- private Handler mHandler = new Handler(Looper.myLooper()) {
- @Override
- public void handleMessage(@NonNull android.os.Message msg) {
- if (msg.what == SEND_APP_BACKGROUND_MSG) {
- //APP切换后台 isOnResume要等于false
- //开启悬浮窗
- if (!isOnResume && AppUtils.isApplicationInBackground(TCStudentLiveRoomActivity.this)) {
- startFloatWindowService();
- }
- return;
- }
- if (msg.what == SEND_JUMP_OTHER_PAGE_MSG) {
- //跳转其他页面时候
- //开启悬浮窗
- if (isOnResume) {
- //如果页面onResume了,就不开启service
- return;
- }
- startFloatWindowService();
- return;
- }
- if (msg.what == OPEN_SHOP_CAR_DIALOG) {
- showShopCarDialog();
- return;
- }
- }
- };
- private V2TIMSDKListener mTIMSDKListener = new V2TIMSDKListener() {
- @Override
- public void onConnecting() {
- super.onConnecting();
- Log.i(TAG, "onConnecting");
- }
- @Override
- public void onConnectSuccess() {
- super.onConnectSuccess();
- Log.i(TAG, "onConnectSuccess");
- if (isConnectImFailed) {
- if (isOnMic()) {
- handleCloseMicEvent();
- }
- presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_JOIN_ROOM);
- presenter.notifyJoinRoomAction(mRoomId, mUserId);
- presenter.getAllGroupAttributes(mRoomId);
- presenter.getAllGroupCounter(mRoomId);
- play();
- }
- isConnectImFailed = false;
- }
- @Override
- public void onConnectFailed(int code, String error) {
- super.onConnectFailed(code, error);
- Log.i(TAG, "onConnectFailed");
- isConnectImFailed = true;
- showLiveStatusView(LIVE_STATUS_ERROR);
- }
- @Override
- public void onKickedOffline() {
- super.onKickedOffline();
- Log.i(TAG, "onKickedOffline");
- finish();
- }
- @Override
- public void onUserSigExpired() {
- super.onUserSigExpired();
- Log.i(TAG, "onUserSigExpired");
- finish();
- }
- @Override
- public void onSelfInfoUpdated(V2TIMUserFullInfo info) {
- super.onSelfInfoUpdated(info);
- Log.i(TAG, "onSelfInfoUpdated");
- }
- @Override
- public void onUserStatusChanged(List<V2TIMUserStatus> userStatusList) {
- super.onUserStatusChanged(userStatusList);
- String myselfUserID = V2TIMManager.getInstance().getLoginUser();
- for (V2TIMUserStatus item : userStatusList) {
- Log.i(TAG, "onUserStatusChanged");
- if (item.getUserID().equals(myselfUserID)) {
- // 自己的状态发生变更
- int statusType = item.getStatusType();
- Log.i(TAG, "onUserStatusChanged statusType:" + statusType);
- if (statusType == V2TIMUserStatus.V2TIM_USER_STATUS_OFFLINE) {
- }
- } else {
- // 其他人的状态发生变更
- }
- }
- }
- };
- private TTMessageAdapter mMessageAdapter;
- private LinearLayoutManager mLinearLayoutManager;
- private boolean isAutoScrollToLast = true;
- private boolean anchorIsOnline = false;//主播是否在线
- private LiveRoomCloseMicTipDialog mRoomCloseMicTipDialog;
- private LiveRoomClosePageOnMicTipDialog mLiveRoomClosePageOnMicTipDialog;
- private String subjectId;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
- super.onCreate(savedInstanceState);
- }
- @Override
- protected AcTtLiveroomLayoutBinding getLayoutView() {
- return AcTtLiveroomLayoutBinding.inflate(getLayoutInflater());
- }
- @Override
- protected void initView() {
- content_view = viewBinding.contentView;
- mVideoView = viewBinding.videoView;
- flVideoContainer = viewBinding.flVideoContainer;
- csVideoContainer = viewBinding.csVideoContainer;
- mGroupViews = viewBinding.groupViews;
- mFlJoinBarrage = viewBinding.flJoinBarrage;
- mIvClose = viewBinding.ivClose;
- mFlSnapUpBarrage = viewBinding.flSnapUpBarrage;
- mIvSwitchVideoOrientation = viewBinding.ivSwitchVideoOrientation;
- mIvSwitchVideoOrientationFull = viewBinding.ivSwitchVideoOrientationFull;
- cs_header_info = viewBinding.csHeaderInfo;
- msgContainer = viewBinding.flRecyclerContainer;
- tv_input = viewBinding.tvInput;
- fl_input = viewBinding.flInput;
- mRecyclerMsg = viewBinding.recyclerMsg;
- mViewLiveStatus = viewBinding.viewLiveStatus.csRoot;
- viewLiveCameraStatus = viewBinding.viewLiveCameraStatus.csRoot;
- mIvLiveStatusCameraCenterIcon = viewBinding.viewLiveCameraStatus.ivCameraCenterIcon;
- mTvLiveCameraStatusTipText = viewBinding.viewLiveCameraStatus.tvLiveCameraStatusTipText;
- mIvLiveStatusCenterIcon = viewBinding.viewLiveStatus.ivCenterIcon;
- mTvLiveStatusTipText = viewBinding.viewLiveStatus.tvLiveStatusTipText;
- mTvJoinBarrage = viewBinding.tvJoinBarrage;
- mTvSnapUpBarrage = viewBinding.tvSnapUpBarrage;
- mTvAddLikeCount = viewBinding.tvAddLikeCount;
- mTvNumPeople = viewBinding.tvNumPeople;
- iv_mic = viewBinding.ivMic;
- mViewShopCarAnim = viewBinding.viewShopCarAnim;
- mIvShopCar = viewBinding.ivShopCar;
- mIvAvatar = viewBinding.ivAvatar;
- mTvRoomCreateName = viewBinding.tvRoomAuthorName;
- mIvVoiceSwitch = viewBinding.ivVoiceSwitch;
- group_tip = viewBinding.viewLiveStatus.groupTip;
- group_loading = viewBinding.viewLiveStatus.groupLoading;
- tv_retry = viewBinding.viewLiveStatus.tvRetry;
- tv_loading = viewBinding.viewLiveStatus.tvLoading;
- mLlMicContainer = viewBinding.llMicContainer;
- subVideoView = viewBinding.subVideoView;
- mRoomId = getIntent().getStringExtra(ROOMID_KEY);
- if (getIntent().hasExtra(SUBJECT_ID_KEY)) {
- subjectId = getIntent().getStringExtra(SUBJECT_ID_KEY);
- }
- if (TextUtils.isEmpty(mRoomId)) {
- ToastUtil.getInstance().show(this, "房间id不可为空");
- finish();
- return;
- }
- mMessageAdapter = new TTMessageAdapter(this);
- mLinearLayoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
- mRecyclerMsg.addItemDecoration(new RecyclerView.ItemDecoration() {
- @Override
- public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
- super.onDraw(c, parent, state);
- }
- });
- mRecyclerMsg.setLayoutManager(mLinearLayoutManager);
- mRecyclerMsg.setAdapter(mMessageAdapter);
- }
- public void setStatusBarColor() {
- ImmersionBar.with(this)
- .keyboardEnable(false)//为了防止软键盘顶起底部布局
- .transparentStatusBar()
- .statusBarDarkFont(false, 0.2f) //原理:如果当前设备支持状态栏字体变色,会设置状态栏字体为黑色,如果当前设备不支持状态栏字体变色,会使当前状态栏加上透明度,否则不执行透明度
- .autoDarkModeEnable(false)
- .flymeOSStatusBarFontColor(R.color.white) //修改flyme OS状态栏字体颜色
- .init(); //必须调用方可沉浸
- }
- @Override
- public void initData() {
- super.initData();
- initIMSdk();
- mUserId = UserHelper.getImUserId();
- //创建 player 对象
- mMLivePlayer = new V2TXLivePlayerImpl(this);
- mMLivePlayer.setRenderFillMode(V2TXLiveDef.V2TXLiveFillMode.V2TXLiveFillModeFill);
- // 设置画面渲染方向
- mMLivePlayer.setRenderRotation(V2TXLiveRotation0);
- //关键 player 对象与界面 view
- mMLivePlayer.setRenderView(mVideoView);
- mMLivePlayer.enableReceiveSeiMessage(true, TTLiveConfig.DEFAULT_PAYLOAD_TYPE);
- presenter.init(this, mRoomId);
- initListener();
- }
- private void initIMSdk() {
- TCIMSdkManager.getInstance().init(getApplication());
- }
- private void initListener() {
- initViewClickListener();
- TCIMSdkManager.getInstance().addEventListener(mTIMSDKListener);
- SoftKeyboardUtil.registerSoftInputChangedListener(getWindow(), this);
- mRecyclerMsg.addOnScrollListener(new RecyclerView.OnScrollListener() {
- @Override
- public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
- super.onScrollStateChanged(recyclerView, newState);
- if (mLinearLayoutManager == null || mMessageAdapter == null) {
- return;
- }
- int lastCompletelyVisibleItemPosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition();
- if (lastCompletelyVisibleItemPosition == mMessageAdapter.getMessageSize() - 1) {
- isAutoScrollToLast = true;
- } else {
- isAutoScrollToLast = false;
- }
- }
- });
- mMLivePlayer.setObserver(new V2TXLivePlayerObserver() {
- @Override
- public void onError(V2TXLivePlayer player, int code, String msg, Bundle extraInfo) {
- super.onError(player, code, msg, extraInfo);
- Log.i("pq", "play error:code=" + code + "---msg:" + msg + "---Bundle:" + extraInfo.toString());
- if (anchorIsOnline) {
- showLiveStatusView(LIVE_STATUS_ERROR);
- }
- }
- @Override
- public void onWarning(V2TXLivePlayer player, int code, String msg, Bundle extraInfo) {
- super.onWarning(player, code, msg, extraInfo);
- Log.i("pq", "play onWarning:code=" + code + "---msg:" + msg + "---Bundle:" + extraInfo.toString());
- }
- @Override
- public void onConnected(V2TXLivePlayer player, Bundle extraInfo) {
- super.onConnected(player, extraInfo);
- Log.i("pq", "play onConnected:" + extraInfo.toString());
- }
- @Override
- public void onRenderVideoFrame(V2TXLivePlayer player, V2TXLiveDef.V2TXLiveVideoFrame videoFrame) {
- super.onRenderVideoFrame(player, videoFrame);
- Log.i("pq", "play onRenderVideoFrame:" + videoFrame);
- hideLiveStatus();
- }
- @Override
- public void onVideoLoading(V2TXLivePlayer player, Bundle extraInfo) {
- super.onVideoLoading(player, extraInfo);
- Log.i("pq", "play onVideoLoading:" + extraInfo.toString());
- }
- @Override
- public void onVideoPlaying(V2TXLivePlayer player, boolean firstPlay, Bundle extraInfo) {
- super.onVideoPlaying(player, firstPlay, extraInfo);
- Log.i("pq", "play onVideoPlaying:" + extraInfo.toString() + "---isFirstPlay:" + firstPlay);
- hideLiveStatus();
- }
- @Override
- public void onReceiveSeiMessage(V2TXLivePlayer player, int payloadType, byte[] data) {
- super.onReceiveSeiMessage(player, payloadType, data);
- Log.i("pq", "play onReceiveSeiMessage:length" + data.length + "---" + payloadType + "---data:" + new String(data));
- if (data != null && data.length > 0) {
- parseSeiMessage(new String(data));
- }
- }
- @Override
- public void onStatisticsUpdate(V2TXLivePlayer player, V2TXLiveDef.V2TXLivePlayerStatistics statistics) {
- super.onStatisticsUpdate(player, statistics);
- // Log.i("pq", "play videoBitrate:" + statistics.videoBitrate);
- // Log.i("pq", "play audioBitrate:" + statistics.audioBitrate);
- // Log.i("pq", "play videoPacketLoss:" + statistics.videoPacketLoss);
- // Log.i("pq", "play audioPacketLoss:" + statistics.audioPacketLoss);
- // Log.i("pq", "play videoBlockRate:" + statistics.videoBlockRate);
- // Log.i("pq", "play aul dioBlockRate:" + statistics.audioBlockRate);
- // Log.i("pq", "play videoTotalBlockTime:" + statistics.videoTotalBlockTime);
- // Log.i("pq", "play audioTotalBlockTime:" + statistics.audioTotalBlockTime);
- // Log.i("pq", "play rtt:" + statistics.rtt);
- }
- });
- mLlMicContainer.setOnEventListener(new TTLiveRoomMicIconView.OnEventListener() {
- @Override
- public void getUserInfoByUserId(String userId) {
- if (presenter != null) {
- presenter.getUserInfoByUserId(userId);
- }
- }
- @Override
- public void onMicStatusUpdate(String userId, String currentMicStatus) {
- boolean isOpen = !TextUtils.equals(currentMicStatus, TTLiveConfig.LIVE_ROOM_MIC_STATUS_ON_VALUE);
- changeMicStatus(userId, isOpen);
- }
- });
- }
- private void changeMicStatus(String userId, boolean isOpenCloseMode) {
- mLlMicContainer.post(new Runnable() {
- @Override
- public void run() {
- if (isOpenCloseMode) {
- //开启闭麦模式
- mLlMicContainer.updateTargetUserMicStatus(userId, TTLiveConfig.LIVE_ROOM_MIC_STATUS_ON_VALUE);
- presenter.setMicrophoneDisable(true);
- presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_MIC_STATUS_CHANGE, mUserId, true);
- } else {
- //关闭闭麦模式
- mLlMicContainer.updateTargetUserMicStatus(userId, TTLiveConfig.LIVE_ROOM_MIC_STATUS_OFF_VALUE);
- presenter.setMicrophoneDisable(false);
- presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_MIC_STATUS_CHANGE, mUserId, false);
- }
- }
- });
- }
- private void parseSeiMessage(String s) {
- try {
- Log.i("pq", "parseSeiMessage:" + s);
- LiveStatusSEMIMsg semiMsg = GsonUtils.fromJson(s, LiveStatusSEMIMsg.class);
- List<LiveStatusSEMIMsg.UserStatusBean> seatUser = semiMsg.getSeatUser();
- mLlMicContainer.refreshAll(seatUser);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void notifyMicContainerDel(String userId) {
- mLlMicContainer.post(new Runnable() {
- @Override
- public void run() {
- mLlMicContainer.deleteMicUser(userId);
- }
- });
- }
- private void notifyMicContainerAdd(String userId) {
- Log.i("pq", "notifyMicContainerAdd:" + userId);
- List<String> seatUser = new ArrayList<>();
- seatUser.add(userId);
- mLlMicContainer.addOnMicUser(seatUser);
- }
- private void hideLiveStatus() {
- if (mViewLiveStatus != null) {
- mViewLiveStatus.setVisibility(View.GONE);
- }
- }
- private void hideLiveCameraStatus() {
- if (viewLiveCameraStatus != null) {
- viewLiveCameraStatus.setVisibility(View.GONE);
- }
- }
- private void initViewClickListener() {
- viewBinding.ivClose.setOnClickListener(this);
- viewBinding.ivSwitchVideoOrientation.setOnClickListener(this);
- viewBinding.flInput.setOnClickListener(this);
- viewBinding.ivMic.setOnClickListener(this);
- viewBinding.iconAddLike.setOnClickListener(this);
- viewBinding.ivSwitchVideoOrientationFull.setOnClickListener(this);
- viewBinding.viewLiveStatus.csRoot.setOnClickListener(this);
- viewBinding.viewShopCarAnim.setOnClickListener(this);
- viewBinding.flVideoContainer.setOnClickListener(this);
- viewBinding.ivVoiceSwitch.setOnClickListener(this);
- viewBinding.viewLiveStatus.tvRetry.setOnClickListener(this);
- }
- @Override
- public void onClick(View view) {
- int id = view.getId();
- if (id == viewBinding.viewLiveStatus.csRoot.getId()) {
- return;
- }
- if (id == R.id.iv_close) {
- if (currentSeatStatus != LiveRoomMsgConstants.MIC_STATUS_NORMAL) {
- showPageCloseOnMicTipDialog();
- } else {
- close();
- }
- return;
- }
- if (id == R.id.iv_switch_video_orientation) {
- //切换横竖屏
- if (UiUtils.isFastClick()) {
- return;
- }
- if (mShopCarDialog != null && mShopCarDialog.isShowing()) {
- return;
- }
- changeOrientation();
- return;
- }
- if (id == R.id.iv_switch_video_orientation_full) {
- //横屏切换竖屏
- changeOrientation();
- return;
- }
- if (id == R.id.fl_input) {
- //底部输入框
- showInputDialog();
- return;
- }
- if (id == R.id.iv_mic) {
- //连麦
- toCheckMicPermission();
- return;
- }
- if (id == R.id.icon_add_like) {
- if (checkAddLikeMode()) {
- return;
- }
- //点赞
- LiveRoomAddLikeHelper.getInstance().handleClick(new LiveRoomAddLikeHelper.OnAddLikeResultCallBack() {
- @Override
- public void onResult(int count) {
- if (presenter != null) {
- presenter.updateGroupAddLike(mRoomId, count);
- // presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_ADD_LIKE_COUNT, count);
- }
- }
- });
- LiveRoomAnimatorHelper.getInstance().startAddLikeAnimation(TCStudentLiveRoomActivity.this, content_view);
- return;
- }
- if (id == R.id.view_shop_car_anim) {
- if (liveIsFinish) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "直播已结束");
- return;
- }
- //购物车
- if (isFullScreen()) {
- changeOrientation();
- android.os.Message message = android.os.Message.obtain();
- message.what = OPEN_SHOP_CAR_DIALOG;
- mHandler.sendMessageDelayed(message, 500);
- } else {
- showShopCarDialog();
- }
- return;
- }
- if (id == R.id.fl_video_container) {
- //点击隐藏头部信息
- if (isFullScreen()) {
- //全屏模式下
- handleHeaderAnim();
- }
- return;
- }
- if (id == R.id.iv_voice_switch) {
- // //静音
- if (isMuteAll) {
- this.isMuteAll = false;
- mIvVoiceSwitch.setImageResource(R.drawable.icon_live_voice_on);
- muteAll(false);
- } else {
- mIvVoiceSwitch.setImageResource(R.drawable.icon_live_voice_off);
- this.isMuteAll = true;
- muteAll(true);
- }
- }
- if (id == R.id.tv_retry) {
- play();
- return;
- }
- }
- @SuppressLint("CheckResult")
- private void toCheckMicPermission() {
- new RxPermissions(this)
- .request(Manifest.permission.RECORD_AUDIO,
- Manifest.permission.WRITE_EXTERNAL_STORAGE)
- .subscribe(permission -> {
- if (permission) {
- handleMicClick();
- } else {
- DialogUtil.showInCenter(getSupportFragmentManager(), com.cooleshow.base.R.layout.common_popu, (holder, dialog) -> {
- TextView tvTitle = holder.getView(com.cooleshow.base.R.id.tv_title);
- TextView tvContent = holder.getView(com.cooleshow.base.R.id.tv_content);
- TextView btncancel = holder.getView(com.cooleshow.base.R.id.btn_cancel);
- TextView btnCommit = holder.getView(com.cooleshow.base.R.id.btn_commit);
- tvTitle.setText("提示");
- tvContent.setText("连麦需要麦克风、储存权限,去设置?");
- btncancel.setOnClickListener(view1 -> {
- dialog.dismiss();
- });
- btnCommit.setOnClickListener(view1 -> {
- PermissionUtils.toSelfSetting(getApplicationContext());
- dialog.dismiss();
- });
- });
- }
- });
- }
- private void handleMicClick() {
- if (!isOnMic()) {
- //非连麦中才判断模式
- if (checkMicMode()) {
- return;
- }
- if (isConnectImFailed) {
- //连接状态异常,暂停连麦
- return;
- }
- }
- showMicManagerDialog();
- }
- /**
- * 是否静音全部
- *
- * @param isMute
- */
- private void muteAll(boolean isMute) {
- mMLivePlayer.setPlayoutVolume(isMute ? 0 : 100);
- if (presenter != null) {
- presenter.muteTRTC(isMute);
- }
- }
- private void showPageCloseOnMicTipDialog() {
- if (mLiveRoomClosePageOnMicTipDialog == null) {
- mLiveRoomClosePageOnMicTipDialog = new LiveRoomClosePageOnMicTipDialog(this);
- mLiveRoomClosePageOnMicTipDialog.setConfirmClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- }
- if (!mLiveRoomClosePageOnMicTipDialog.isShowing()) {
- mLiveRoomClosePageOnMicTipDialog.show();
- }
- mLiveRoomClosePageOnMicTipDialog.setTitle("提示");
- mLiveRoomClosePageOnMicTipDialog.setContent("连麦中,是否退出房间?");
- }
- private void close() {
- //断开连接,结束页面
- onBackPressed();
- }
- @Override
- public void onBackPressed() {
- if (liveIsFinish) {
- super.onBackPressed();
- return;
- }
- if (isFullScreen()) {
- changeOrientation();
- } else {
- boolean permissionOverlay = FloatWindowHelper.requestOverlayPermission(this);
- if (!permissionOverlay) {
- showOpenOverlayPermissionTipDialog();
- } else {
- showExitLiveTipDialog();
- }
- }
- }
- private void showOpenOverlayPermissionTipDialog() {
- OpenOverlayPermissionTipDialog overlayPermissionTipDialog = new OpenOverlayPermissionTipDialog(this);
- overlayPermissionTipDialog.setConfirmClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- overlayPermissionTipDialog.dismiss();
- Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
- startActivityForResult(intent, FloatWindowHelper.REQUEST_OVERLAY_CODE);
- }
- });
- overlayPermissionTipDialog.show();
- overlayPermissionTipDialog.setCancelClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- overlayPermissionTipDialog.dismiss();
- finish();
- }
- });
- }
- /**
- * 退出直播间提示弹窗
- */
- private void showExitLiveTipDialog() {
- LiveRoomExitTipDialog2 liveRoomExitTipDialog2 = new LiveRoomExitTipDialog2(this);
- liveRoomExitTipDialog2.setConfirmClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- liveRoomExitTipDialog2.show();
- }
- private void showInputDialog() {
- if (roomInfo == null) {
- return;
- }
- if (checkChatMode()) return;
- if (mInputBarDialog == null) {
- mInputBarDialog = new InputBarDialog(TCStudentLiveRoomActivity.this, new InputBar.InputBarListener() {
- @Override
- public boolean onClickSend(String message) {
- //发送消息
- if (checkChatMode()) {
- return false;
- }
- if (TextUtils.isEmpty(message)) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "消息不能为空");
- return false;
- }
- if (message.length() > TTLiveConfig.LIVE_MAX_INPUT_TEXT_LENGTH) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "聊天消息需在40个字以内哦");
- return false;
- }
- if (LiveMessageHelper.isQuickAction()) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "您说话太快啦");
- return false;
- }
- sendTextMessage(message);
- return true;
- }
- @Override
- public boolean onClickEmoji() {
- return false;
- }
- });
- mInputBarDialog.setOnShowListener(new DialogInterface.OnShowListener() {
- @Override
- public void onShow(DialogInterface dialog) {
- if (mInputBarDialog != null) {
- mInputBarDialog.showInput();
- }
- }
- });
- }
- if (!mInputBarDialog.isShowing()) {
- mInputBarDialog.show();
- }
- }
- private void sendTextMessage(String message) {
- presenter.sendTextMessage(message);
- }
- /**
- * 检查点赞按钮是否可用
- *
- * @return
- */
- private boolean checkAddLikeMode() {
- if (liveIsFinish) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "直播已结束");
- return true;
- }
- // if (isEnableAll) {
- // ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "您已被管理员禁言");
- // return true;
- // }
- if (isConnectImFailed) {
- //连接状态异常,暂停点赞
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "网络连接状态异常");
- return true;
- }
- return false;
- }
- private void changeOrientation() {
- int currentOrientation = getCurrentOrientation();
- boolean isNeedFullScreen = currentOrientation != Configuration.ORIENTATION_LANDSCAPE;
- if (isNeedFullScreen) {
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- } else {
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- }
- }
- private void startFloatWindowService() {
- boolean hasPermission = FloatWindowHelper.requestOverlayPermission(this);
- if (hasPermission) {
- Intent intent = new Intent(this, FloatingWindowService.class);
- initServiceConnection();
- intent.putExtra("isPc", isPcClientLive);
- bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
- }
- }
- private void initServiceConnection() {
- if (serviceConnection == null) {
- serviceConnection = new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- if (service instanceof FloatingWindowService.MyBinder) {
- FloatingWindowService.MyBinder mBinder = (FloatingWindowService.MyBinder) service;
- ArrayList<View> list = new ArrayList();
- list.add(getVideoView());
- mBinder.addTTVideoView(list);
- mBinder.setOnEventListener(new FloatingWindowService.OnEventListener() {
- @Override
- public void onServiceDestroy() {
- if (flVideoContainer != null) {
- flVideoContainer.addView(getVideoView());
- }
- }
- @Override
- public void onUnbindService() {
- muteAll(true);
- unbindService();
- }
- });
- }
- }
- @Override
- public void onServiceDisconnected(ComponentName name) {
- if (flVideoContainer != null) {
- flVideoContainer.addView(getVideoView());
- }
- }
- };
- }
- }
- /**
- * 销毁悬浮窗service
- */
- private void unbindService() {
- if (serviceConnection != null) {
- try {
- boolean isExist = AppUtils.isServiceWork(this, FloatingWindowService.CLASS_PATH);
- if (isExist) {
- unbindService(serviceConnection);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- public View getVideoView() {
- return csVideoContainer;
- }
- private boolean isFullScreen() {
- return getCurrentOrientation() == Configuration.ORIENTATION_LANDSCAPE;
- }
- private int getCurrentOrientation() {
- return getResources().getConfiguration().orientation;
- }
- @Override
- public void onConfigurationChanged(@NonNull Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- //改变videoView容器布局尺寸
- resetVideoContainer(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE);
- }
- private void resetVideoContainer(boolean isFullScreen) {
- if (isFullScreen) {
- if (isPcClientLive) {
- //隐藏消息列表
- mGroupViews.setVisibility(View.GONE);
- mIvClose.setVisibility(View.GONE);
- //隐藏弹幕消息
- mFlJoinBarrage.clearAnimation();
- mFlJoinBarrage.setVisibility(View.GONE);
- mFlSnapUpBarrage.clearAnimation();
- mFlSnapUpBarrage.setVisibility(View.GONE);
- //隐藏竖屏全屏按钮
- mIvSwitchVideoOrientation.setVisibility(View.GONE);
- mIvSwitchVideoOrientationFull.setVisibility(View.VISIBLE);
- } else {
- //不是PC端直播
- mIvSwitchVideoOrientation.setVisibility(View.GONE);
- mIvSwitchVideoOrientationFull.setVisibility(View.GONE);
- }
- ConstraintSet set = new ConstraintSet();
- set.clone(content_view);
- set.clear(flVideoContainer.getId());
- if (!isPcClientLive) {
- //如果是非PC端直播,还需要设置下消息列表控件位置
- set.clear(msgContainer.getId());
- set.connect(msgContainer.getId(), ConstraintSet.TOP, R.id.view_center, ConstraintSet.BOTTOM, DensityUtil.dp2px(TCStudentLiveRoomActivity.this, 50));
- set.connect(msgContainer.getId(), ConstraintSet.LEFT, content_view.getId(), ConstraintSet.LEFT, 0);
- set.connect(msgContainer.getId(), ConstraintSet.RIGHT, content_view.getId(), ConstraintSet.RIGHT, 0);
- set.connect(msgContainer.getId(), ConstraintSet.BOTTOM, fl_input.getId(), ConstraintSet.TOP, DensityUtil.dp2px(TCStudentLiveRoomActivity.this, 10));
- }
- set.connect(flVideoContainer.getId(), ConstraintSet.TOP, content_view.getId(), ConstraintSet.TOP, 0);
- set.connect(flVideoContainer.getId(), ConstraintSet.LEFT, content_view.getId(), ConstraintSet.LEFT, 0);
- set.connect(flVideoContainer.getId(), ConstraintSet.RIGHT, content_view.getId(), ConstraintSet.RIGHT, 0);
- set.connect(flVideoContainer.getId(), ConstraintSet.BOTTOM, content_view.getId(), ConstraintSet.BOTTOM, 0);
- set.applyTo(content_view);
- } else {
- //pc端直播,控制居中显示,以及videoview容器的宽高
- if (cs_header_info.getTranslationY() != 0) {
- //还原显示头部信息
- handleHeaderAnim();
- }
- if (isPcClientLive) {
- mGroupViews.setVisibility(View.VISIBLE);
- mIvClose.setVisibility(View.VISIBLE);
- mIvSwitchVideoOrientation.setVisibility(View.VISIBLE);
- mIvSwitchVideoOrientationFull.setVisibility(View.GONE);
- }
- ConstraintSet set = new ConstraintSet();
- set.clone(content_view);
- set.clear(flVideoContainer.getId());
- set.connect(flVideoContainer.getId(), ConstraintSet.TOP, cs_header_info.getId(), ConstraintSet.BOTTOM, DensityUtil.dp2px(TCStudentLiveRoomActivity.this, 121));
- set.connect(flVideoContainer.getId(), ConstraintSet.LEFT, content_view.getId(), ConstraintSet.LEFT, 0);
- set.connect(flVideoContainer.getId(), ConstraintSet.RIGHT, content_view.getId(), ConstraintSet.RIGHT, 0);
- int maxHeightAtRatio16_9 = UiUtils.getMaxHeightAtRatio16_9(TCStudentLiveRoomActivity.this);
- set.constrainHeight(flVideoContainer.getId(), maxHeightAtRatio16_9);
- set.applyTo(content_view);
- }
- }
- private void handleHeaderAnim() {
- float animOffset = cs_header_info.getTranslationY();
- if (animOffset == 0) {
- //隐藏头部信息
- int bottom = cs_header_info.getBottom();
- if (hideHeaderInfoAnim == null) {
- hideHeaderInfoAnim = ObjectAnimator.ofFloat(cs_header_info, "translationY", 0, -bottom);
- hideHeaderInfoAnim.setDuration(500);
- }
- hideHeaderInfoAnim.start();
- } else {
- //显示头部信息
- if (showHeaderInfoAnim == null) {
- showHeaderInfoAnim = ObjectAnimator.ofFloat(cs_header_info, "translationY", animOffset, 0);
- showHeaderInfoAnim.setDuration(500);
- }
- showHeaderInfoAnim.start();
- }
- }
- /**
- * 控制聊天模式
- *
- * @param isEnableChat
- */
- @Override
- public void switchChatMode(boolean isEnableChat) {
- //控制聊天模式
- Log.i("pq", "聊天禁止:" + isEnableChat);
- this.isEnableChat = isEnableChat;
- }
- @Override
- public void changeMicControlMode(boolean isEnableMic) {
- //禁止连麦模式
- if (isFinishing() || isDestroyed()) {
- return;
- }
- Log.i("pq", "receive mic mode control msg 禁麦模式:" + isEnableMic);
- this.isEnableMic = isEnableMic;
- if (isEnableMic && isOnApplyMic()) {
- handleCloseMicEvent();
- }
- }
- @Override
- public void liveRoomOffline() {
- //关闭直播间
- ToastUtil.getInstance().show(this, "直播已结束");
- this.liveIsFinish = true;
- //取消连麦
- if (mMicManagerDialog != null) {
- mMicManagerDialog.dismiss();
- }
- presenter.exitRoom();
- showLiveStatusView(LIVE_STATUS_IS_OFFLINE);
- hideDialog();
- }
- @Override
- public void receiveJoinMessage(TCUserEnterMessage joinRoomMessage) {
- if (!checkActivityExist()) {
- return;
- }
- if (joinRoomMessage == null) {
- return;
- }
- if (isCanShowBarrage()) {
- mTvJoinBarrage.setText(getString(R.string.enter_live_tip_str, TTLiveHelper.getMessageName(joinRoomMessage)));
- showBarrageViewAnim(mFlJoinBarrage);
- }
- }
- /**
- * 显示弹幕消息
- */
- private void showBarrageViewAnim(View targetView) {
- if (mFlJoinBarrage.getVisibility() == View.VISIBLE || mFlSnapUpBarrage.getVisibility() == View.VISIBLE) {
- return;
- }
- LiveRoomAnimatorHelper.getInstance().startBarrageViewAnimation(this, targetView);
- hideBarrageView();
- }
- /**
- * 隐藏弹幕消息
- */
- private void hideBarrageView() {
- mHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- if (mFlJoinBarrage != null) {
- mFlJoinBarrage.setVisibility(View.GONE);
- }
- if (mFlSnapUpBarrage != null) {
- mFlSnapUpBarrage.setVisibility(View.GONE);
- }
- }
- }, TTLiveConfig.LIVE_HIDE_BARRAGE_VIEW_TIME);
- }
- /**
- * 判断是否显示弹幕消息
- *
- * @return
- */
- private boolean isCanShowBarrage() {
- if (isFullScreen()) {
- return false;
- }
- return mFlJoinBarrage.getVisibility() != View.VISIBLE && mFlSnapUpBarrage.getVisibility() != View.VISIBLE;
- }
- @Override
- public void receiveSnapUpMessage(TCUserSnappingUpMessage onSnappingUpMessage) {
- //收到抢购消息
- if (!checkActivityExist()) {
- return;
- }
- if (onSnappingUpMessage == null) {
- return;
- }
- if (isCanShowBarrage()) {
- mTvSnapUpBarrage.setText(getString(R.string.live_snap_up_tip_str, TTLiveHelper.getMessageName(onSnappingUpMessage)));
- showBarrageViewAnim(mFlSnapUpBarrage);
- }
- }
- @Override
- public void liveGoodsChange(String goodsContent) {
- //直播间商品发生变化
- if (!checkActivityExist()) {
- return;
- }
- if (mShopCarDialog != null) {
- mShopCarDialog.changeGoods(goodsContent);
- }
- }
- @Override
- public void onAddLikeMessage(TCSyncAddLikeMessage addLikeMessage) {
- if (isFinishing() || isDestroyed()) {
- return;
- }
- if (addLikeMessage == null) {
- return;
- }
- SendUserInfo sendUserInfo = addLikeMessage.getSendUserInfo();
- if (sendUserInfo != null && isOwn(sendUserInfo.getSendUserId())) {
- return;
- }
- // if (addLikeMessage != null) {
- // if (mTvAddLikeCount != null) {
- // currentAddLikeCount = addLikeMessage.getCount();
- // updateAddLikeCountView();
- // }
- // }
- }
- private void updateAddLikeCountView(long count) {
- this.currentAddLikeCount = count;
- if (mTvAddLikeCount != null) {
- mTvAddLikeCount.setText(getString(R.string.live_room_add_like_count_str, LiveMemberHelper.getStarsCountText(currentAddLikeCount)));
- }
- }
- @Override
- public void syncMemberCount(int count) {
- //同步成员数量
- Log.i("pq", "syncMemberCount" + count);
- if (isFinishing() || isDestroyed()) {
- return;
- }
- // setPeopleCount(String.valueOf(count));
- }
- public void setPeopleCount(String count) {
- if (mTvNumPeople != null) {
- mTvNumPeople.setText(String.format(Locale.getDefault(), "%s人", LiveMemberHelper.getMemberCountText(count)));
- }
- }
- @Override
- public void onUserKickOutMsg(TCKickOutUserMessage userKickOutMessage) {
- //用户被踢出消息
- if (!checkActivityExist()) {
- return;
- }
- if (userKickOutMessage == null || !isOwn(userKickOutMessage.getTargetId())) {
- return;
- }
- String targetId = userKickOutMessage.getTargetId();
- Log.i("pq", "receive kickOut msg targetId:" + targetId);
- finish();
- }
- private boolean isOwn(String targetUserId) {
- return TextUtils.equals(mUserId, targetUserId);
- }
- @Override
- public void seatResponse(TCUserSeatResponseMessage rcUserSeatResponseMessage) {
- if (isFinishing() || isDestroyed()) {
- return;
- }
- if (rcUserSeatResponseMessage == null || !isOwn(rcUserSeatResponseMessage.getAudienceId())) {
- return;
- }
- if (rcUserSeatResponseMessage != null) {
- int type = rcUserSeatResponseMessage.getType();
- if (type == LiveRoomMsgConstants.MIC_RESPONSE_AGREE) {
- //主播同意
- // ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "主播同意连麦");
- if (presenter != null) {
- presenter.joinMic(mUserId, roomInfo.getUserSig());
- }
- return;
- }
- if (type == LiveRoomMsgConstants.MIC_RESPONSE_DISAGREE) {
- //主播拒绝
- updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_NORMAL);
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, getString(R.string.create_refuse_seat_tip));
- return;
- }
- }
- }
- @Override
- public void onInviteSeatMic(TCUserSeatApplyMessage seatApplyMessage) {
- if (isFinishing() || isDestroyed()) {
- return;
- }
- if (seatApplyMessage == null || !isOwn(seatApplyMessage.getAudienceId())) {
- return;
- }
- if (seatApplyMessage.getType() == LiveRoomMsgConstants.MIC_ACTION_INVITE_SEAT_BY_CREATE) {
- //主讲人邀请观众上麦
- showInviteSeatDialog();
- return;
- }
- if (seatApplyMessage.getType() == LiveRoomMsgConstants.MIC_ACTION_CANCEL_INVITE_SEAT_BY_CREATE) {
- //主讲人取消邀请观众上麦
- if (mInviteSeatMicTipDialog != null) {
- mInviteSeatMicTipDialog.dismiss();
- }
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, getString(R.string.create_recall_seat_invite_tip));
- return;
- }
- if (seatApplyMessage.getType() == LiveRoomMsgConstants.MIC_ACTION_CANCEL_SEAT_BY_CREATE) {
- //主讲人讲观众抱下麦
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "主讲人断开连麦");
- if (presenter != null) {
- presenter.exitRoom();
- }
- }
- }
- private void showShopCarDialog() {
- if (roomInfo == null || TextUtils.isEmpty(roomInfo.getShopCarUrl())) {
- return;
- }
- if (mShopCarDialog == null) {
- mShopCarDialog = new LiveRoomShopCarDialog(this);
- mShopCarDialog.setOnEventListener(new LiveRoomShopCarDialog.OnEventListener() {
- @Override
- public void onOpenDetail(String url) {
- mShopCarDialog.dismiss();
- //发送XXX正在抢购消息
- presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_ON_SNAP_UP);
- sendShowFloatWindowAction(SEND_JUMP_OTHER_PAGE_MSG);
- ARouter.getInstance()
- .build(RouterPath.WebCenter.ACTIVITY_HTML)
- .withString(WebConstants.WEB_URL, url)
- .withString(WebConstants.WEB_TITLE, "商品详情")
- .navigation();
- }
- });
- }
- if (!mShopCarDialog.isShowing()) {
- mShopCarDialog.show();
- }
- mShopCarDialog.setRoomId(mRoomId, roomInfo.getShopCarUrl());
- }
- private void showInviteSeatDialog() {
- if (mInviteSeatMicTipDialog == null) {
- mInviteSeatMicTipDialog = new LiveRoomInviteSeatMicTipDialog(this);
- mInviteSeatMicTipDialog.setCancelable(false);
- mInviteSeatMicTipDialog.setCanceledOnTouchOutside(false);
- mInviteSeatMicTipDialog.setViewClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (v.getId() == R.id.tv_sure) {
- //被邀请连麦->同意连麦
- if (presenter != null && roomInfo != null) {
- if (!checkMicMode2()) {
- presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_CANCEL_SEAT_AGREE_RESPONSE, getSpeakerId(), getSpeakerName());
- presenter.joinMic(mUserId, roomInfo.getUserSig());
- }
- }
- }
- if (v.getId() == R.id.tv_cancel) {
- //被邀请连麦->拒绝连麦
- if (presenter != null) {
- presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_CANCEL_SEAT_DISAGREE_RESPONSE, getSpeakerId(), getSpeakerName());
- }
- //重置一下连麦状态
- handleCloseMicEvent();
- }
- mInviteSeatMicTipDialog.dismiss();
- }
- });
- }
- if (!mInviteSeatMicTipDialog.isShowing()) {
- mInviteSeatMicTipDialog.show();
- }
- String defaultNick = "主讲人";
- if (roomInfo != null && !TextUtils.isEmpty(roomInfo.speakerName)) {
- defaultNick = roomInfo.speakerName;
- }
- mInviteSeatMicTipDialog.setContent(defaultNick);
- }
- @Override
- public void onUserUnusualLogout(TCUserLogOutUnNormalMessage loginOutUnusualMessage) {
- if (isFinishing() || isDestroyed()) {
- return;
- }
- if (loginOutUnusualMessage == null || !isOwn(loginOutUnusualMessage.getTargetId())) {
- return;
- }
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "直播加载异常,请退出重试");
- Log.i("pq", "unusual logout");
- finish();
- }
- @Override
- public void showLoading() {
- showLiveStatusView(LIVE_STATUS_LOADING);
- }
- @Override
- public void hideLoading() {
- hideLiveStatus();
- }
- @Override
- public void onLivePause() {
- if (isFinishing() || isDestroyed()) {
- return;
- }
- showLiveStatusView(LIVE_STATUS_IS_REST);
- this.liveIsPause = true;
- // ToastUtil.getInstance().show(this, getString(R.string.live_is_pause_str));
- handleCloseMicEvent();
- if (mMicManagerDialog != null) {
- mMicManagerDialog.dismiss();
- }
- }
- @Override
- public void changeBlackUserStatus(String userId, boolean isAddBlack) {
- if (isFinishing() || isDestroyed()) {
- return;
- }
- if (isOwn(userId)) {
- isEnableAll = isAddBlack;
- if (isEnableAll) {
- //取消连麦
- if (currentSeatStatus != LiveRoomMsgConstants.MIC_STATUS_NORMAL) {
- handleCloseMicEvent();
- }
- }
- updateInputTip();
- }
- }
- private void updateInputTip() {
- if (tv_input == null) {
- return;
- }
- if (isEnableAll) {
- tv_input.setText(getString(R.string.unable_input_tip_str));
- } else {
- tv_input.setText(getString(R.string.live_input_tips_str));
- }
- }
- @Override
- public void onUnderAllMic() {
- if (isFinishing() || isDestroyed()) {
- return;
- }
- if (isOnMic()) {
- if (presenter != null) {
- presenter.exitRoom();
- }
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, getString(R.string.down_mic_by_create_tip));
- if (presenter != null && roomInfo != null) {
- presenter.buildUnderMicResponseMessage(mUserId, roomInfo.speakerId, roomInfo.speakerName);
- }
- }
- }
- @Override
- public void onRefuseAllMicApply() {
- if (isFinishing() || isDestroyed()) {
- return;
- }
- if (mMicManagerDialog != null) {
- mMicManagerDialog.dismiss();
- }
- if (isOnApplyMic()) {
- updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_NORMAL);
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, getString(R.string.create_refuse_seat_tip));
- if (roomInfo != null) {
- presenter.buildResponseMessage(mUserId, roomInfo.speakerImUserId, roomInfo.speakerName);
- }
- }
- }
- @Override
- public void onUserStartPublish() {
- if (!checkActivityExist()) {
- return;
- }
- }
- @Override
- public void enterLiveRoomSuccess() {
- //重置记录状态,等待回调触发准确值
- hasMainStream = false;
- hasSubStream = false;
- if (mMLivePlayer != null) {
- mMLivePlayer.stopPlay();
- }
- config3AParamsIfNeed();
- muteAll(isMuteAll);
- updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_CONNECT_SUCCESS);
- if (mMicManagerDialog != null) {
- mMicManagerDialog.dismiss();
- }
- presenter.startPublish(mUserId);
- notifyMicContainerAdd(mUserId);
- changeMicStatus(mUserId, isMuteAllMic);
- }
- private void config3AParamsIfNeed() {
- if (!TextUtils.isEmpty(subjectId)) {
- presenter.config3AParamsFromSubject(subjectId);
- }
- }
- private boolean hasMainStream = false;//是否有主路流
- private boolean hasSubStream = false;//是否有辅路流
- @Override
- public void onUserVideoAvailable(String userId, boolean available) {
- if (TextUtils.equals(userId, getSpeakerId())) {
- Log.i(TAG, "onUserVideoAvailable:" + available);
- hasMainStream = available;
- startRemote();
- }
- }
- @Override
- public void onUserSubStreamAvailable(String userId, boolean available) {
- if (TextUtils.equals(userId, getSpeakerId())) {
- Log.i(TAG, "onUserSubStreamAvailable:" + available);
- hasSubStream = available;
- startRemote();
- }
- }
- public void startRemote() {
- if (hasMainStream && hasSubStream) {
- //主辅流都有的情况
- subVideoView.setVisibility(View.VISIBLE);
- presenter.startMainRemoteView(getSpeakerId(), isPcClientLive, subVideoView);
- presenter.startSubRemoteView(getSpeakerId(), isPcClientLive, mVideoView);
- return;
- }
- if (hasMainStream) {
- //主流情况
- subVideoView.setVisibility(View.GONE);
- presenter.stopSubRemoteView(getSpeakerId());
- presenter.startMainRemoteView(getSpeakerId(), isPcClientLive, mVideoView);
- return;
- }
- if (hasSubStream) {
- //单辅流情况
- subVideoView.setVisibility(View.GONE);
- presenter.stopMainRemoteView(getSpeakerId());
- presenter.startSubRemoteView(getSpeakerId(), isPcClientLive, mVideoView);
- return;
- }
- }
- @Override
- public void enterLiveRoomError() {
- }
- @Override
- public void onExitRoomSuccess() {
- Log.i("pq", "onExitRoomSuccess");
- currentSeatStatus = LiveRoomMsgConstants.MIC_STATUS_NORMAL;
- updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_NORMAL);
- if (!TextUtils.isEmpty(mUserId)) {
- notifyMicContainerDel(mUserId);
- }
- if (presenter != null) {
- presenter.stopAllRemoteView(getSpeakerId());
- presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_DOWN_SEAT_MIC);
- }
- play();
- }
- @Override
- public void onStopPublishing() {
- }
- @Override
- public void onPublishSuccess() {
- updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_CONNECT_SUCCESS);
- if (mMicManagerDialog != null) {
- mMicManagerDialog.dismiss();
- }
- }
- @Override
- public void onRemoteUserEnterRoom(String userId) {
- if (!TextUtils.equals(userId, getSpeakerId())) {
- Log.i("pq", "onRemoteUserEnterRoom:" + userId);
- notifyMicContainerAdd(userId);
- }
- }
- @Override
- public void onRemoteUserLeaveRoom(String userId, int reason) {
- if (!TextUtils.equals(userId, getSpeakerId())) {
- Log.i("pq", "onRemoteUserLeaveRoom:" + userId);
- notifyMicContainerDel(userId);
- }
- }
- @Override
- public void onStatistics(TRTCStatistics statistics) {
- }
- @Override
- public void getFriendInfoSuccess(FriendInfoBean friendInfoBean) {
- if (isFinishing() || isDestroyed()) {
- return;
- }
- if (mLlMicContainer != null && friendInfoBean != null) {
- String friendAvatar = friendInfoBean.getFriendAvatar();
- mLlMicContainer.updateTargetUserInfo(new TTUserInfo(friendInfoBean.getImFriendId(), friendInfoBean.friendNickname, !TextUtils.isEmpty(friendAvatar) ? Uri.parse(friendAvatar) : null));
- }
- }
- @Override
- public void receiveSEIMsg(String userId, byte[] data) {
- if (TextUtils.equals(userId, getSpeakerId())) {
- // parseSeiMessage(new String(data));
- }
- }
- @Override
- public void onGroupAttributeChanged(String groupID, Map<String, String> groupAttributeMap) {
- if (TextUtils.equals(groupID, mRoomId)) {
- JSONObject jsonObject = new JSONObject(groupAttributeMap);
- parseGroupAttribute(jsonObject);
- }
- }
- @Override
- public void onGroupCounterChanged(String groupID, String key, long newValue) {
- if (TextUtils.equals(groupID, mRoomId)) {
- if (TextUtils.equals(TTLiveConfig.LIVE_ROOM_LIKES_KEY, key)) {
- //点赞数同步
- Log.i("pq", "likes newValue:" + newValue);
- updateAddLikeCountView(newValue);
- }
- }
- }
- @Override
- public void getAllGroupCounterSuccess(Map<String, Long> map) {
- if (!checkActivityExist()) {
- return;
- }
- if (map != null && map.size() > 0) {
- //获取群点赞数
- if (map.containsKey(TTLiveConfig.LIVE_ROOM_LIKES_KEY)) {
- Long result = map.get(TTLiveConfig.LIVE_ROOM_LIKES_KEY);
- if (result != null) {
- updateAddLikeCountView(result);
- }
- }
- }
- }
- @Override
- public void onMicStatusControl(String userId, boolean muteMic) {
- if (!checkActivityExist()) {
- return;
- }
- if (!isOwn(userId)) {
- return;
- }
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, muteMic ? "主讲人已将您的麦克风关闭" : "主讲人已将您的麦克风开启");
- changeMicStatus(userId, muteMic);
- }
- @Override
- public void onUserAudioAvailable(String userId, boolean available) {
- if (!checkActivityExist()) {
- return;
- }
- if (mLlMicContainer != null) {
- mLlMicContainer.updateTargetUserMicStatus(userId, available ? TTLiveConfig.LIVE_ROOM_MIC_STATUS_OFF_VALUE : TTLiveConfig.LIVE_ROOM_MIC_STATUS_ON_VALUE);
- }
- }
- @Override
- public void onLiveForceKick(TCLiveForceKickMessage messageContent) {
- if (!checkActivityExist()) {
- return;
- }
- if (messageContent != null) {
- ArrayList<String> targetIds = messageContent.getTargetIds();
- if (targetIds != null && targetIds.size() > 0) {
- //判断个人
- for (int i = 0; i < targetIds.size(); i++) {
- boolean isContainerOwner = isOwn(targetIds.get(i));
- if (isContainerOwner) {
- liveRoomOffline();
- showLiveCourseStatusChangeTip(messageContent.getReason());
- return;
- }
- }
- } else {
- //全体
- liveRoomOffline();
- showLiveCourseStatusChangeTip(messageContent.getReason());
- }
- }
- }
- private void showLiveCourseStatusChangeTip(String tip) {
- if (TextUtils.isEmpty(tip)) {
- tip = "当前课程已调整,请退出直播间";
- }
- CommonConfirmDialog confirmDialog = new CommonConfirmDialog(this);
- confirmDialog.show();
- confirmDialog.setOnConfirmClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- confirmDialog.setContent(tip);
- confirmDialog.hideCancel();
- confirmDialog.setCancelable(false);
- confirmDialog.setCanceledOnTouchOutside(false);
- }
- @Override
- public void getAllGroupAttributesSuccess(Object o) {
- Log.i("pq", "getAllGroupAttributesSuccess:" + o.toString());
- if (o == null) {
- return;
- }
- try {
- JSONObject jsonObject = new JSONObject(o.toString());
- parseGroupAttribute(jsonObject);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- private void parseGroupAttribute(JSONObject groupAttributeJson) {
- Log.i("pq", "group:" + groupAttributeJson.toString());
- if (groupAttributeJson != null) {
- //主播状态
- checkAnchorStatus(groupAttributeJson);
- // //点赞数
- // getLikesFromAttributes(groupAttributeJson);
- //人数
- getMemberCountFromAttributes(groupAttributeJson);
- //全局禁言状态
- getGlobalBanStatus(groupAttributeJson);
- //全员闭麦模式
- getMuteAllMicStatus(groupAttributeJson);
- }
- }
- private void getMuteAllMicStatus(JSONObject groupAttributeJson) {
- String muteAllMicStatus = groupAttributeJson.optString(TTLiveConfig.LIVE_ROOM_MIC_STATUS_MODE_KEY);
- if (!TextUtils.isEmpty(muteAllMicStatus)) {
- Log.i("pq", " groupAttribute muteAllMicStatus:" + muteAllMicStatus);
- boolean result = TextUtils.equals(muteAllMicStatus, TTLiveConfig.STATUS_ON);
- if (result != isMuteAllMic) {
- //有变化
- if (isOnMic()) {
- changeMicStatus(mUserId, result);
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, result ? "主讲人已将您的麦克风关闭" : "主讲人已将您的麦克风开启");
- }
- }
- isMuteAllMic = result;
- }
- }
- private void getGlobalBanStatus(JSONObject groupAttributeJson) {
- String globalBanStatus = groupAttributeJson.optString(TTLiveConfig.LIVE_ROOM_GLOBAL_BAN_KEY);
- if (!TextUtils.isEmpty(globalBanStatus)) {
- Log.i("pq", " groupAttribute globalBanStatus:" + globalBanStatus);
- if (TextUtils.equals(globalBanStatus, TTLiveConfig.STATUS_ON)) {
- //全局禁言开启
- isEnableChat = true;
- } else {
- isEnableChat = false;
- }
- }
- }
- private void getCameraStatus(JSONObject groupAttributeJson) {
- String cameraStatus = groupAttributeJson.optString(TTLiveConfig.LIVE_ROOM_ANCHOR_CAMERA_KEY);
- if (!TextUtils.isEmpty(cameraStatus)) {
- Log.i("pq", " groupAttribute cameraStatus:" + cameraStatus);
- if (TextUtils.equals(cameraStatus, TTLiveConfig.STATUS_OFF)) {
- //主播关闭摄像头
- showLiveStatusView(LIVE_STATUS_IS_CLOSE_VIDEO);
- } else {
- hideLiveCameraStatus();
- }
- }
- }
- private void getMemberCountFromAttributes(JSONObject groupAttributeMap) {
- String member_online = groupAttributeMap.optString(TTLiveConfig.LIVE_ROOM_MEMBER_ONLINE_KEY);
- Log.i("pq", "member_online:" + member_online);
- if (!TextUtils.isEmpty(member_online)) {
- setPeopleCount(member_online);
- }
- }
- private void getLikesFromAttributes(JSONObject groupAttributeJson) {
- String likes = groupAttributeJson.optString(TTLiveConfig.LIVE_ROOM_LIKES_KEY);
- Log.i("pq", "likes:" + likes);
- if (!TextUtils.isEmpty(likes)) {
- try {
- int i = Integer.parseInt(likes);
- updateAddLikeCountView(i);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- private void checkAnchorStatus(JSONObject groupAttributeJson) {
- if (liveIsFinish) {
- return;
- }
- String anchorStatus = groupAttributeJson.optString(TTLiveConfig.LIVE_ROOM_LIVE_STATUS_KEY);
- Log.i("pq", "checkAnchorStatus:" + anchorStatus);
- if (TextUtils.isEmpty(anchorStatus)) {
- return;
- }
- if (TextUtils.equals(anchorStatus, TTLiveConfig.STATUS_ON)) {
- //如果在线
- anchorIsOnline = true;
- TCStudentLiveRoomActivity.this.liveIsPause = false;
- play();
- //主播摄像头状态
- getCameraStatus(groupAttributeJson);
- } else {
- //不在线
- anchorIsOnline = false;
- showLiveStatusView(LIVE_STATUS_IS_REST);
- mLlMicContainer.delAll();
- handleCloseMicEvent();
- }
- }
- private void updateMicIcon(int micStatus) {
- //主线程更新
- iv_mic.post(new Runnable() {
- @Override
- public void run() {
- currentSeatStatus = micStatus;
- if (micStatus == LiveRoomMsgConstants.MIC_STATUS_NORMAL) {
- iv_mic.setImageResource(R.drawable.icon_mic_unconnect);
- }
- if (micStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECTING) {
- iv_mic.setImageResource(R.drawable.icon_mic_connecting);
- }
- if (micStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECT_SUCCESS) {
- iv_mic.setImageResource(R.drawable.icon_mic_conected);
- }
- }
- });
- }
- /**
- * 关闭一些交互弹窗
- */
- private void hideDialog() {
- //关闭邀请弹窗
- if (mInviteSeatMicTipDialog != null && mInviteSeatMicTipDialog.isShowing()) {
- mInviteSeatMicTipDialog.dismiss();
- }
- //关闭商品弹窗
- if (mShopCarDialog != null && mShopCarDialog.isShowing()) {
- mShopCarDialog.dismiss();
- }
- }
- private void showLiveStatusView(int status) {
- Log.i("pq", "showLiveStatusView:" + status);
- if (isFinishing() || isDestroyed()) {
- return;
- }
- if (mViewLiveStatus == null) {
- return;
- }
- //显示视频画面已经关闭页面
- mViewLiveStatus.post(new Runnable() {
- @Override
- public void run() {
- mViewLiveStatus.setVisibility(status == LIVE_STATUS_IS_CLOSE_VIDEO ? View.GONE : View.VISIBLE);
- if (status == LIVE_STATUS_IS_REST) {
- group_loading.setVisibility(View.GONE);
- tv_retry.setVisibility(View.GONE);
- group_tip.setVisibility(View.VISIBLE);
- hideLiveCameraStatus();
- stopPlay();
- mIvLiveStatusCenterIcon.setImageResource(R.drawable.icon_live_room_rest_bg);
- mTvLiveStatusTipText.setText("休息一下,马上回来!");
- mTvLiveStatusTipText.setTextSize(12);
- mTvLiveStatusTipText.setBackgroundResource(R.drawable.shape_gray_14dp);
- } else if (status == LIVE_STATUS_IS_CLOSE_VIDEO) {
- viewLiveCameraStatus.setVisibility(View.VISIBLE);
- mIvLiveStatusCameraCenterIcon.setImageResource(R.drawable.icon_live_room_close_video);
- mTvLiveCameraStatusTipText.setText("主讲人已关闭画面!");
- mTvLiveCameraStatusTipText.setTextSize(12);
- mTvLiveCameraStatusTipText.setBackgroundResource(R.drawable.shape_gray_14dp);
- } else if (status == LIVE_STATUS_IS_OFFLINE) {
- group_loading.setVisibility(View.GONE);
- tv_retry.setVisibility(View.GONE);
- group_tip.setVisibility(View.VISIBLE);
- hideLiveCameraStatus();
- stopPlay();
- mLlMicContainer.delAll();
- mIvLiveStatusCenterIcon.setImageResource(R.drawable.icon_live_end_tip);
- mTvLiveStatusTipText.setText("直播已结束!");
- mTvLiveStatusTipText.setTextSize(14);
- mTvLiveStatusTipText.setBackgroundColor(Color.TRANSPARENT);
- } else if (status == LIVE_STATUS_LOADING) {
- group_loading.setVisibility(View.VISIBLE);
- group_tip.setVisibility(View.GONE);
- tv_retry.setVisibility(View.GONE);
- tv_loading.setText("视频加载中");
- } else if (status == LIVE_STATUS_ERROR) {
- group_loading.setVisibility(View.GONE);
- tv_retry.setVisibility(View.VISIBLE);
- group_tip.setVisibility(View.VISIBLE);
- hideLiveCameraStatus();
- stopPlay();
- mIvLiveStatusCenterIcon.setImageResource(R.drawable.icon_live_room_close_video);
- mTvLiveStatusTipText.setText("视频加载失败");
- mTvLiveStatusTipText.setTextSize(14);
- mTvLiveStatusTipText.setBackgroundResource(R.drawable.shape_gray_14dp);
- }
- }
- });
- }
- private void stopPlay() {
- if (mMLivePlayer != null) {
- mMLivePlayer.stopPlay();
- }
- }
- /**
- * 取消连麦
- */
- private void handleCloseMicEvent() {
- if (currentSeatStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECTING) {
- //连接中取消连接
- if (presenter != null) {
- presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_CANCEL_SEAT_APPLY, getSpeakerId(), getSpeakerName());
- updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_NORMAL);
- }
- }
- if (currentSeatStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECT_SUCCESS) {
- if (presenter != null) {
- presenter.exitRoom();
- }
- }
- }
- @Override
- protected void onResume() {
- super.onResume();
- this.isOnResume = true;
- unbindService();
- //取消全部静音
- if (!isMuteAll) {
- muteAll(false);
- }
- // if (mMLivePlayer != null) {
- // mMLivePlayer.resumeAudio();
- // mMLivePlayer.resumeVideo();
- // }
- }
- @Override
- protected void onPause() {
- super.onPause();
- isOnResume = false;
- sendShowFloatWindowAction(SEND_APP_BACKGROUND_MSG);
- // if (mMLivePlayer != null) {
- // mMLivePlayer.pauseVideo();
- // mMLivePlayer.pauseAudio();
- // }
- }
- private void sendShowFloatWindowAction(int what) {
- android.os.Message message = android.os.Message.obtain();
- message.what = what;
- mHandler.sendMessageDelayed(message, SEND_SHOW_FLOAT_WINDOW_TIME);
- }
- @Override
- protected TTLiveRoomPresenter createPresenter() {
- return new TTLiveRoomPresenter();
- }
- @Override
- public void getRoomInfoSuccess(LiveRoomInfoBean roomInfo) {
- if (!checkActivityExist()) {
- return;
- }
- if (roomInfo != null) {
- this.roomInfo = roomInfo;
- LOG.i(TAG, "getRoomInfoSuccess:" + roomInfo.toString());
- String userSig = roomInfo.getUserSig();
- if (!TextUtils.isEmpty(userSig)) {
- presenter.connectIM(mUserId, userSig);
- // play();
- }
- isPcClientLive = TextUtils.equals(roomInfo.getOs(), "pc") || TextUtils.equals(roomInfo.getOs(), "client");
- mMLivePlayer.setRenderFillMode(isPcClientLive ? V2TXLiveDef.V2TXLiveFillMode.V2TXLiveFillModeFit : V2TXLiveDef.V2TXLiveFillMode.V2TXLiveFillModeFill);
- resetVideoContainer(!isPcClientLive);
- // if (!TextUtils.isEmpty(roomInfo.roomConfig)) {
- // try {
- // JSONObject jsonObject = new JSONObject(roomInfo.roomConfig);
- // //聊天模式
- // int chatCtrlMode = jsonObject.optInt("whether_chat", 0);
- // //连麦模式
- // int micCtrlMode = jsonObject.optInt("whether_mic", 0);
- // //购物车是否显示
- // int shopCarMode = jsonObject.optInt("whether_view_shop_cart", 0);
- // isEnableChat = chatCtrlMode == 1;
- // isEnableMic = micCtrlMode == 1;
- //
- //
- // } catch (JSONException e) {
- // e.printStackTrace();
- // }
- // }
- if (TextUtils.isEmpty(roomInfo.getShopCarUrl())) {
- //隐藏购物车
- mViewShopCarAnim.setVisibility(View.GONE);
- mIvShopCar.setVisibility(View.GONE);
- } else {
- //显示购物车
- mViewShopCarAnim.setVisibility(View.VISIBLE);
- mIvShopCar.setVisibility(View.INVISIBLE);
- }
- //黑名单模式
- isEnableAll = roomInfo.blacklistFlag == 1;//1是黑名单 0否
- updateInputTip();
- updateAddLikeCountView(roomInfo.likeNum);
- if (mTvNumPeople != null) {
- // int peopleCount = roomInfo.lookNum + 1;//加上自己
- setPeopleCount(String.valueOf(roomInfo.lookNum));
- }
- if (mIvAvatar != null) {
- //创建人头像
- Glide.with(TCStudentLiveRoomActivity.this).load(roomInfo.speakerPic).placeholder(R.drawable.icon_default_head).error(R.drawable.icon_default_head).into(mIvAvatar);
- }
- if (mTvRoomCreateName != null) {
- //创建人昵称
- mTvRoomCreateName.setText(roomInfo.speakerName);
- }
- if (mMessageAdapter != null) {
- mMessageAdapter.setRoomAuthorId(roomInfo.speakerId);
- }
- }
- }
- @Override
- public void getRoomInfoError(Throwable throwable) {
- if (!checkActivityExist()) {
- return;
- }
- finish();
- }
- @Override
- public void connectIMError(int errorCode, String errorMsg) {
- hideLoading();
- ToastUtil.getInstance().show(this, "加入直播间群聊异常,请退出重试");
- }
- @Override
- public void loginIMSuccess() {
- if (presenter != null) {
- presenter.joinGroup(mRoomId);
- }
- }
- @Override
- public void joinGroupSuccess() {
- hideLoading();
- presenter.bindGroupListener();
- presenter.getAllGroupAttributes(mRoomId);
- presenter.getAllGroupCounter(mRoomId);
- presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_JOIN_ROOM);
- presenter.notifyJoinRoomAction(mRoomId, mUserId);
- }
- private void play() {
- if (roomInfo != null && roomInfo.getLiveRoomConfig() != null) {
- if (isOnMic()) {
- return;
- }
- if (liveIsPause || liveIsFinish || !anchorIsOnline) {
- return;
- }
- if (mMLivePlayer.isPlaying() == 1) {
- return;
- }
- //关键 player 对象与界面 view
- mMLivePlayer.setRenderView(mVideoView);
- LiveRoomInfoBean.LiveRoomConfigBean liveRoomConfig = roomInfo.getLiveRoomConfig();
- String playUrl = getPlayUrl(liveRoomConfig.getPlayUrl(), roomInfo.getRoomId(), roomInfo.speakerImUserId);
- Log.i("pq", "playUrl:" + playUrl);
- showLiveStatusView(LIVE_STATUS_LOADING);
- subVideoView.setVisibility(View.GONE);
- mMLivePlayer.startLivePlay(playUrl);
- }
- }
- private String getPlayUrl(String domain, String roomId, String targetId) {
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append("rtmp://")
- .append(domain)
- .append("/live/")
- .append(roomId)
- .append("_")
- .append(targetId);
- // String url = "rtmp://cdn1.dayaedu.com/live/12233333_LIVE?12233333_LIVE";
- return stringBuilder.toString();
- }
- @Override
- public void joinGroupError(int code, String des) {
- hideLoading();
- Log.i(TAG, "joinGroupError code:" + code + "des" + des);
- ToastUtil.getInstance().show(this, "加入直播群组失败,请退出重试");
- }
- @Override
- public void addMessageContent(TTMessage ttMessage) {
- //添加单条消息至页面
- Log.i("pq", "收到需要显示msg:" + ttMessage);
- //只处理直播间消息,以及本直播间消息
- if (mMessageAdapter != null) {
- mMessageAdapter.addMessage(ttMessage);
- if (mRecyclerMsg != null && mLinearLayoutManager != null) {
- mRecyclerMsg.post(new Runnable() {
- @Override
- public void run() {
- if (isAutoScrollToLast) {
- if (mRecyclerMsg != null) {
- mRecyclerMsg.scrollToPosition(mMessageAdapter.getItemCount() - 1);
- }
- } else {
- Log.i("pq", "收到消息,不自动滚动");
- }
- }
- });
- }
- }
- }
- private boolean isOnApplyMic() {
- return currentSeatStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECTING;
- }
- private boolean isOnMic() {
- return currentSeatStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECT_SUCCESS;
- }
- private void showMicManagerDialog() {
- if (mMicManagerDialog == null) {
- mMicManagerDialog = new LiveRoomMicManagerDialog(this);
- mMicManagerDialog.setOnEventListener(new LiveRoomMicManagerDialog.OnEventListener() {
- @Override
- public void onApplyMic() {
- //申请连麦
- handleMicEvent();
- mMicManagerDialog.setMicStatus(LiveRoomMsgConstants.MIC_STATUS_CONNECTING);
- mMicManagerDialog.dismiss();
- }
- @Override
- public void onApplyCancel() {
- //取消申请连麦
- handleMicEvent();
- }
- @Override
- public void onCloseMic() {
- //关闭连麦
- handleMicEvent();
- }
- });
- }
- if (!mMicManagerDialog.isShowing()) {
- mMicManagerDialog.show();
- }
- if (roomInfo != null) {
- mMicManagerDialog.setLiveTeacherInfo(roomInfo.speakerPic);
- }
- mMicManagerDialog.setMicStatus(currentSeatStatus);
- }
- private void handleMicEvent() {
- if (currentSeatStatus == LiveRoomMsgConstants.MIC_STATUS_NORMAL) {
- //未连麦状态 申请连麦
- if (presenter != null) {
- presenter.handleAction(LiveRoomMsgConstants.ACTION_SEND_SEAT_APPLY, getSpeakerId(), getSpeakerName());
- }
- updateMicIcon(LiveRoomMsgConstants.MIC_STATUS_CONNECTING);
- } else {
- //取消连麦
- showCloseMicTipDialog();
- }
- }
- public String getSpeakerId() {
- if (roomInfo != null) {
- return roomInfo.speakerImUserId;
- }
- return "";
- }
- public String getSpeakerName() {
- if (roomInfo != null) {
- return roomInfo.speakerName;
- }
- return "";
- }
- private void showCloseMicTipDialog() {
- if (mRoomCloseMicTipDialog == null) {
- mRoomCloseMicTipDialog = new LiveRoomCloseMicTipDialog(this);
- mRoomCloseMicTipDialog.setConfirmClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- handleCloseMicEvent();
- mRoomCloseMicTipDialog.dismiss();
- if (mMicManagerDialog != null) {
- mMicManagerDialog.dismiss();
- }
- }
- });
- }
- if (!mRoomCloseMicTipDialog.isShowing()) {
- mRoomCloseMicTipDialog.show();
- }
- mRoomCloseMicTipDialog.setContent(getString(currentSeatStatus == LiveRoomMsgConstants.MIC_STATUS_CONNECTING ? R.string.cancel_seat_on_connecting : R.string.cancel_seat_on_connected));
- }
- /**
- * 检查聊天模式
- */
- public boolean checkChatMode() {
- if (liveIsFinish) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "直播已结束");
- return true;
- }
- if (isEnableAll) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "您已被管理员禁言");
- return true;
- }
- if (isEnableChat) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "管理员关闭聊天");
- return true;
- }
- return false;
- }
- /**
- * 检查mic模式
- */
- public boolean checkMicMode() {
- if (!anchorIsOnline) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "老师暂停中,暂时无法接受申请");
- return true;
- }
- if (liveIsPause) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "老师暂停中,暂时无法接受申请");
- return true;
- }
- if (liveIsFinish) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "直播已结束");
- return true;
- }
- if (isEnableAll) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "您已被管理员禁言");
- return true;
- }
- if (isEnableMic) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "管理员关闭连麦申请");
- return true;
- }
- return false;
- }
- /**
- * 检查mic模式
- */
- public boolean checkMicMode2() {
- if (!anchorIsOnline) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "老师暂停中,暂时无法接受申请");
- return true;
- }
- if (liveIsPause) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "老师暂停中,暂时无法接受申请");
- return true;
- }
- if (liveIsFinish) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "直播已结束");
- return true;
- }
- if (isEnableAll) {
- ToastUtil.getInstance().show(TCStudentLiveRoomActivity.this, "您已被管理员禁言");
- return true;
- }
- return false;
- }
- @Override
- public void finish() {
- super.finish();
- //前置通知离开接口
- notifyLeave();
- }
- private void notifyLeave() {
- if (presenter != null) {
- //通知离开房间
- presenter.notifyLeaveRoomAction();
- }
- }
- @Override
- public void onSoftInputChanged(int height) {
- Log.i("pq", "height" + height);
- if (height == 0) {
- //软键盘隐藏
- Log.i("pq", "SoftInput hide");
- if (mInputBarDialog != null && mInputBarDialog.isShowing()) {
- mInputBarDialog.dismiss();
- }
- } else {
- //软键盘弹出
- Log.i("pq", "SoftInput show");
- }
- }
- @Override
- public void onDestroy() {
- if (presenter != null) {
- presenter.release();
- }
- super.onDestroy();
- if (mHandler != null) {
- mHandler.removeCallbacksAndMessages(null);
- }
- if (mMLivePlayer != null) {
- mMLivePlayer.stopPlay();
- }
- //取消动画
- if (hideHeaderInfoAnim != null) {
- hideHeaderInfoAnim.cancel();
- hideHeaderInfoAnim = null;
- }
- if (showHeaderInfoAnim != null) {
- showHeaderInfoAnim.cancel();
- showHeaderInfoAnim = null;
- }
- SoftKeyboardUtil.unregisterSoftInputChangedListener(getWindow());
- LiveRoomAnimatorHelper.getInstance().releaseAnimator();
- LiveRoomAddLikeHelper.getInstance().release();
- TRTCSdkManager.getInstance().release();
- TCIMSdkManager.getInstance().quitGroup(mRoomId);
- TCIMSdkManager.getInstance().release(mTIMSDKListener);
- }
- }
|