加入了多房间登录操作来解决同一设备推流同时拉流
This commit is contained in:
@@ -5,10 +5,11 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
|
||||
import com.mogo.cloud.util.YuvToolUtils;
|
||||
import com.zhidao.manager.camera.FrameBufferCallBack;
|
||||
import com.zhidao.manager.camera.ZDCameraManager;
|
||||
@@ -34,16 +35,25 @@ public abstract class BaseLiveActivity extends AppCompatActivity {
|
||||
// 当前直播的状态
|
||||
protected ToggleButton tbLiveStatus;
|
||||
// 相机数据预览
|
||||
protected SurfaceView surfaceView;
|
||||
protected SurfaceView surfacePreviewView;
|
||||
|
||||
// 查看指定车机的画面
|
||||
protected SurfaceView surfacePlayView;
|
||||
// 查看直播按钮
|
||||
protected ToggleButton liveToggleBtn;
|
||||
// 要查看的车机SN
|
||||
protected EditText etLookRoomId;
|
||||
// WIFI状态
|
||||
protected TextView tvWifiState;
|
||||
|
||||
private ZDCameraManager zdCameraManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_live_push);
|
||||
setContentView(R.layout.activity_live_play_and_push);
|
||||
|
||||
surfaceView = findViewById(R.id.surfaceView);
|
||||
surfacePreviewView = findViewById(R.id.surfacePreviewView);
|
||||
btnLive = findViewById(R.id.btnLive);
|
||||
btnLive.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
Toast.makeText(getApplicationContext(), buttonView.getText(), Toast.LENGTH_SHORT).show();
|
||||
@@ -67,6 +77,15 @@ public abstract class BaseLiveActivity extends AppCompatActivity {
|
||||
|
||||
tbLiveStatus = findViewById(R.id.tbLiveStatus);
|
||||
|
||||
surfacePlayView = findViewById(R.id.surfacePlayView);
|
||||
etLookRoomId = findViewById(R.id.etLookRoomId);
|
||||
liveToggleBtn = findViewById(R.id.liveToggleBtn);
|
||||
liveToggleBtn.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
Toast.makeText(getApplicationContext(), buttonView.getText(), Toast.LENGTH_SHORT).show();
|
||||
togglePlay(isChecked);
|
||||
});
|
||||
tvWifiState = findViewById(R.id.tvWifiState);
|
||||
|
||||
initCamer();
|
||||
}
|
||||
|
||||
@@ -106,7 +125,7 @@ public abstract class BaseLiveActivity extends AppCompatActivity {
|
||||
});
|
||||
|
||||
// 这里是纯预览
|
||||
surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
|
||||
surfacePreviewView.getHolder().addCallback(new SurfaceHolder.Callback() {
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
Log.i(TAG, "addSurfaceCallBack id");
|
||||
@@ -157,4 +176,11 @@ public abstract class BaseLiveActivity extends AppCompatActivity {
|
||||
*/
|
||||
public abstract void toggleCameraState(boolean isLive);
|
||||
|
||||
/**
|
||||
* 开关查看直播
|
||||
*
|
||||
* @param isPlay true-查看直播,false-不查看直播
|
||||
*/
|
||||
public abstract void togglePlay(boolean isPlay);
|
||||
|
||||
}
|
||||
126
app/src/main/java/com/mogo/cloud/LivePlayAndPushActivity.java
Normal file
126
app/src/main/java/com/mogo/cloud/LivePlayAndPushActivity.java
Normal file
@@ -0,0 +1,126 @@
|
||||
package com.mogo.cloud;
|
||||
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mogo.cloud.live.listener.ILiveStatusListener;
|
||||
import com.mogo.cloud.live.manager.ILiveStreamManager;
|
||||
import com.mogo.cloud.live.manager.LiveStreamManagerImpl;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.cloud.trafficlive.api.ITrafficLiveCallBack;
|
||||
import com.mogo.cloud.trafficlive.api.MoGoAiCloudTrafficLive;
|
||||
import com.mogo.cloud.wifi.IWifiStateListener;
|
||||
import com.mogo.cloud.wifi.WifiStateManager;
|
||||
|
||||
|
||||
/**
|
||||
* 推流和拉流页面
|
||||
*/
|
||||
public class LivePlayAndPushActivity extends BaseLiveActivity implements ITrafficLiveCallBack, IWifiStateListener {
|
||||
public static final String TAG = "PushActivity";
|
||||
|
||||
private String liveSn;
|
||||
|
||||
ILiveStreamManager liveStreamManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
WifiStateManager.getInstance().registerWifiStateListener(this);
|
||||
|
||||
// 初始化直播流管理
|
||||
liveStreamManager = LiveStreamManagerImpl.getInstance(this.getApplication(),
|
||||
MoGoAiCloudClientConfig.getInstance().getThirdPartyDeviceId());
|
||||
|
||||
// 设置状态回调
|
||||
liveStreamManager.setLiveStatusChangeCallback(new ILiveStatusListener() {
|
||||
@Override
|
||||
public void onChange(String camId, int status) {
|
||||
tbLiveStatus.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (status == 0) {
|
||||
tbLiveStatus.setTextColor(getResources().getColor(R.color.colorStartLive));
|
||||
tbLiveStatus.setChecked(true);
|
||||
} else {
|
||||
tbLiveStatus.setTextColor(getResources().getColor(R.color.colorStopLive));
|
||||
tbLiveStatus.setChecked(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoFrame(byte[] bytes, int bytesLength) {
|
||||
//Log.i(TAG, "onVideoFrame byte length: " + bytesLength);
|
||||
if (liveStreamManager != null) {
|
||||
// 将摄像头采集的YUV数据推送到ZEGO
|
||||
liveStreamManager.notifyYUVData(bytes, 1280, 720, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleLive(boolean isLive) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleCameraState(boolean isLive) {
|
||||
Log.i(TAG, "toggleCameraState isLive: " + isLive);
|
||||
if (isLive) {
|
||||
// 上报摄像头状态,1-可用,2-不可用
|
||||
liveStreamManager.uploadCamStatus(1, 1);
|
||||
} else {
|
||||
liveStreamManager.uploadCamStatus(2, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void togglePlay(boolean isPlay) {
|
||||
if (isPlay) {
|
||||
liveSn = etLookRoomId.getText().toString().trim();
|
||||
MoGoAiCloudTrafficLive.viewVehicleHeadLive(this.getApplication(),
|
||||
liveSn, surfacePlayView, this);
|
||||
} else {
|
||||
MoGoAiCloudTrafficLive.stopLive(liveSn);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (liveStreamManager != null) {
|
||||
// 停止
|
||||
liveStreamManager.stopLiveStream();
|
||||
// 释放资源
|
||||
liveStreamManager.release();
|
||||
}
|
||||
|
||||
MoGoAiCloudTrafficLive.stopLive(liveSn);
|
||||
MoGoAiCloudTrafficLive.destroyLive();
|
||||
WifiStateManager.getInstance().unRegisterWifiStateListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLive() {
|
||||
Log.d(TAG, "开始直播 onLive");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisConnect() {
|
||||
Log.d(TAG, "失去连接 onDisConnect");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String errorMsg) {
|
||||
Log.d(TAG, "发生错误 onError msg: " + errorMsg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWifiState(WifiInfo wifiInfo) {
|
||||
tvWifiState.setText("wifiLevel: " + Math.abs(wifiInfo.getRssi()));
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,10 @@ public class LivePushActivity extends BaseLiveActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// 初始化直播流管理
|
||||
liveStreamManager = LiveStreamManagerImpl.getInstance(this,
|
||||
liveStreamManager = LiveStreamManagerImpl.getInstance(this.getApplication(),
|
||||
MoGoAiCloudClientConfig.getInstance().getThirdPartyDeviceId());
|
||||
|
||||
// 设置状态回调
|
||||
liveStreamManager.setLiveStatusChangeCallback(new ILiveStatusListener() {
|
||||
@Override
|
||||
public void onChange(String camId, int status) {
|
||||
@@ -67,6 +69,11 @@ public class LivePushActivity extends BaseLiveActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void togglePlay(boolean isPlay) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.text.TextUtils;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
import com.mogo.cloud.network.NetworkActivity;
|
||||
import com.mogo.cloud.passport.IMoGoTokenCallback;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient;
|
||||
@@ -19,6 +18,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
private Button btnJumpNetWorkPort;
|
||||
private Button btnJumpRealTime;
|
||||
private Button btnJumpRoadCondition;
|
||||
private Button btnJumpLivePlayAndPush;
|
||||
private Button btnJumpLivePush;
|
||||
private Button btnJumpLivePlay;
|
||||
|
||||
@@ -66,6 +66,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
btnJumpLivePlayAndPush = findViewById(R.id.btnJumpLivePlayAndPush);
|
||||
btnJumpLivePlayAndPush.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(MainActivity.this, LivePlayAndPushActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
btnJumpLivePush = findViewById(R.id.btnJumpLivePush);
|
||||
btnJumpLivePush.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(MainActivity.this, LivePushActivity.class);
|
||||
|
||||
Reference in New Issue
Block a user