主播开播时增加网络环境检测和提升
This commit is contained in:
parent
33b889cb79
commit
50fa5831c0
@ -4,8 +4,8 @@ ext {
|
|||||||
buildToolsVersion: "29.0.2",
|
buildToolsVersion: "29.0.2",
|
||||||
minSdkVersion : 23,
|
minSdkVersion : 23,
|
||||||
targetSdkVersion : 34,
|
targetSdkVersion : 34,
|
||||||
versionCode : 904,
|
versionCode : 906,
|
||||||
versionName : "6.8.3"
|
versionName : "6.8.4"
|
||||||
]
|
]
|
||||||
manifestPlaceholders = [
|
manifestPlaceholders = [
|
||||||
//正式、
|
//正式、
|
||||||
|
@ -68,6 +68,7 @@ public class SWManager extends BaseCacheManager {
|
|||||||
private FrameLayout pkContainer; //pk主播视图1
|
private FrameLayout pkContainer; //pk主播视图1
|
||||||
private FrameLayout linkUserContainer;//连麦用户视图
|
private FrameLayout linkUserContainer;//连麦用户视图
|
||||||
private onRtcEngineListener onRtcEngineListener;
|
private onRtcEngineListener onRtcEngineListener;
|
||||||
|
private onNetWorkListener onNetWorkListener;
|
||||||
private List<String> drPkUserInfo = new ArrayList<>();
|
private List<String> drPkUserInfo = new ArrayList<>();
|
||||||
private ImageTrackOptions imageTrackOptions = null;
|
private ImageTrackOptions imageTrackOptions = null;
|
||||||
|
|
||||||
@ -81,6 +82,9 @@ public class SWManager extends BaseCacheManager {
|
|||||||
public void setOnRtcEngineListener(SWManager.onRtcEngineListener onRtcEngineListener) {
|
public void setOnRtcEngineListener(SWManager.onRtcEngineListener onRtcEngineListener) {
|
||||||
this.onRtcEngineListener = onRtcEngineListener;
|
this.onRtcEngineListener = onRtcEngineListener;
|
||||||
}
|
}
|
||||||
|
public void setOnNetWorkListener(SWManager.onNetWorkListener onNetWorkListener) {
|
||||||
|
this.onNetWorkListener = onNetWorkListener;
|
||||||
|
}
|
||||||
|
|
||||||
public SWManager(Context context) {
|
public SWManager(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -530,6 +534,26 @@ public class SWManager extends BaseCacheManager {
|
|||||||
super.onLocalVideoStateChanged(source, state, error);
|
super.onLocalVideoStateChanged(source, state, error);
|
||||||
L.eSw("onLocalVideoStateChanged_source" + source + " state_" + state + " error_" + error);
|
L.eSw("onLocalVideoStateChanged_source" + source + " state_" + state + " error_" + error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnectionStateChanged(int state, int reason) {
|
||||||
|
super.onConnectionStateChanged(state, reason);
|
||||||
|
L.eSw("onConnectionStateChanged: state = " + state + " reason = " + reason );
|
||||||
|
|
||||||
|
// 使用wifi和数据切换的时候,也会引起这个回调
|
||||||
|
if (state == 4 && reason == 2){
|
||||||
|
// 断网了
|
||||||
|
if (onNetWorkListener != null){
|
||||||
|
onNetWorkListener.onConnectionFail();
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if (state == 3 && reason == 15){
|
||||||
|
// 断网后又恢复了
|
||||||
|
if (onNetWorkListener != null){
|
||||||
|
onNetWorkListener.onConnectionSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void refreshToken() {
|
private void refreshToken() {
|
||||||
@ -552,6 +576,11 @@ public class SWManager extends BaseCacheManager {
|
|||||||
public void release() {
|
public void release() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface onNetWorkListener {
|
||||||
|
void onConnectionSuccess();
|
||||||
|
|
||||||
|
void onConnectionFail();
|
||||||
|
}
|
||||||
public interface onRtcEngineListener {
|
public interface onRtcEngineListener {
|
||||||
void onOpenSuccess(String channel, int uid);
|
void onOpenSuccess(String channel, int uid);
|
||||||
|
|
||||||
|
@ -182,6 +182,8 @@ public class LiveAudienceActivity extends LiveActivity {
|
|||||||
private LiveBean mLiveBean;
|
private LiveBean mLiveBean;
|
||||||
//当前直播间下标
|
//当前直播间下标
|
||||||
private int mCurrentItem, mCurrentPage;
|
private int mCurrentItem, mCurrentPage;
|
||||||
|
|
||||||
|
// 这里集成直播间UI
|
||||||
private static PortraitLiveManager manager;
|
private static PortraitLiveManager manager;
|
||||||
private int mLastPosition = -1;
|
private int mLastPosition = -1;
|
||||||
|
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
package com.yunbao.live.dialog;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.cardview.widget.CardView;
|
||||||
|
|
||||||
|
import com.lxj.xpopup.XPopup;
|
||||||
|
import com.yunbao.common.dialog.AbsDialogCenterPopupWindow;
|
||||||
|
import com.yunbao.live.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author: plx
|
||||||
|
* Date: 2024/11/11
|
||||||
|
* Description:
|
||||||
|
*/
|
||||||
|
@SuppressLint("ViewConstructor")
|
||||||
|
public class NetWorkTipDialog extends AbsDialogCenterPopupWindow {
|
||||||
|
// 1 断网 2 恢复
|
||||||
|
private int type;
|
||||||
|
private TextView text_tip;
|
||||||
|
private CardView close_btn;
|
||||||
|
|
||||||
|
public NetWorkTipDialog(@NonNull Context context,int type) {
|
||||||
|
super(context);
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void buildDialog(XPopup.Builder builder) {
|
||||||
|
builder.dismissOnTouchOutside(false).dismissOnBackPressed(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int bindLayoutId() {
|
||||||
|
return R.layout.dialog_network_tip;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
text_tip = (TextView)findViewById(R.id.text_tip);
|
||||||
|
close_btn = (CardView)findViewById(R.id.close_btn);
|
||||||
|
|
||||||
|
if (type == 1){
|
||||||
|
text_tip.setText(R.string.connection_fail);
|
||||||
|
}else {
|
||||||
|
text_tip.setText(R.string.connection_success);
|
||||||
|
}
|
||||||
|
|
||||||
|
close_btn.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -45,6 +45,7 @@ import com.yunbao.live.R;
|
|||||||
import com.yunbao.live.activity.LiveActivity;
|
import com.yunbao.live.activity.LiveActivity;
|
||||||
import com.yunbao.live.activity.LiveSwAnchorActivity;
|
import com.yunbao.live.activity.LiveSwAnchorActivity;
|
||||||
import com.yunbao.live.bean.DrPkbean;
|
import com.yunbao.live.bean.DrPkbean;
|
||||||
|
import com.yunbao.live.dialog.NetWorkTipDialog;
|
||||||
import com.yunbao.live.event.LiveAudienceEvent;
|
import com.yunbao.live.event.LiveAudienceEvent;
|
||||||
import com.yunbao.common.http.LiveHttpConsts;
|
import com.yunbao.common.http.LiveHttpConsts;
|
||||||
import com.yunbao.common.http.LiveHttpUtil;
|
import com.yunbao.common.http.LiveHttpUtil;
|
||||||
@ -230,6 +231,9 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder {
|
|||||||
initRtcEngine();
|
initRtcEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NetWorkTipDialog netWorkTipOkDialog;
|
||||||
|
private NetWorkTipDialog netWorkTipFailDialog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化声网SDK
|
* 初始化声网SDK
|
||||||
*/
|
*/
|
||||||
@ -247,6 +251,46 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder {
|
|||||||
@Override
|
@Override
|
||||||
public void onUserOffline(int uid) {
|
public void onUserOffline(int uid) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
swManager.setOnNetWorkListener(new SWManager.onNetWorkListener() {
|
||||||
|
@Override
|
||||||
|
public void onConnectionSuccess() {
|
||||||
|
// 显示成功连接网络通知
|
||||||
|
if (mContext != null){
|
||||||
|
((Activity) mContext).runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (netWorkTipFailDialog != null && netWorkTipFailDialog.isShow()){
|
||||||
|
netWorkTipFailDialog.dismiss();
|
||||||
|
}
|
||||||
|
if (netWorkTipOkDialog == null){
|
||||||
|
netWorkTipOkDialog = new NetWorkTipDialog(mContext, 2);
|
||||||
|
}
|
||||||
|
netWorkTipOkDialog.showDialog();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnectionFail() {
|
||||||
|
if (mContext != null){
|
||||||
|
((Activity) mContext).runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// 显示断网通知
|
||||||
|
if (netWorkTipOkDialog != null && netWorkTipOkDialog.isShow()){
|
||||||
|
netWorkTipOkDialog.dismiss();
|
||||||
|
}
|
||||||
|
if (netWorkTipFailDialog == null){
|
||||||
|
netWorkTipFailDialog = new NetWorkTipDialog(mContext, 1);
|
||||||
|
}
|
||||||
|
netWorkTipFailDialog.showDialog();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
53
live/src/main/res/layout/dialog_network_tip.xml
Normal file
53
live/src/main/res/layout/dialog_network_tip.xml
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
app:cardCornerRadius="10dp"
|
||||||
|
app:cardBackgroundColor="@color/white"
|
||||||
|
app:cardElevation="0dp"
|
||||||
|
>
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:paddingBottom="15dp"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_tip"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_marginTop="15dp"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:textSize="15sp"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<androidx.cardview.widget.CardView
|
||||||
|
android:layout_width="90dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
app:cardBackgroundColor="#FFB813"
|
||||||
|
app:cardCornerRadius="15dp"
|
||||||
|
app:cardElevation="0dp"
|
||||||
|
android:layout_marginTop="15dp"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/text_tip"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:id="@+id/close_btn"
|
||||||
|
>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:text="@string/confirm"
|
||||||
|
android:gravity="center"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
@ -162,5 +162,6 @@
|
|||||||
<string name="live_room_push_details">詳情</string>
|
<string name="live_room_push_details">詳情</string>
|
||||||
<string name="live_room_push_like_an">喜歡主播就關注ta吧~</string>
|
<string name="live_room_push_like_an">喜歡主播就關注ta吧~</string>
|
||||||
<string name="message_1">點擊查看</string>
|
<string name="message_1">點擊查看</string>
|
||||||
|
<string name="connection_fail">网络连接中断,请检查您的网络</string>
|
||||||
|
<string name="connection_success">已连接网络</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -165,4 +165,6 @@
|
|||||||
<string name="live_room_push_details">Details</string>
|
<string name="live_room_push_details">Details</string>
|
||||||
<string name="live_room_push_like_an">If you like this anchor, please subscribe to him.</string>
|
<string name="live_room_push_like_an">If you like this anchor, please subscribe to him.</string>
|
||||||
<string name="message_1">Click to view</string>
|
<string name="message_1">Click to view</string>
|
||||||
|
<string name="connection_fail">The network connection is interrupted. Please check your network.</string>
|
||||||
|
<string name="connection_success">The network has been restored.</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user