fix bug of pull live

This commit is contained in:
zhongchao
2021-02-07 11:33:04 +08:00
parent 6a9fcbd28c
commit d7a3baa4ae
11 changed files with 70 additions and 92 deletions

View File

@@ -9,12 +9,11 @@ import android.widget.ToggleButton;
import androidx.appcompat.app.AppCompatActivity;
import com.mogo.cloud.live.listener.ILiveProgressListener;
import com.mogo.cloud.live.manager.MoGoLiveManager;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.cloud.trafficlive.api.ITrafficLiveCallBack;
import com.mogo.cloud.trafficlive.api.MoGoAiCloudTrafficLive;
public class LivePlayActivity extends AppCompatActivity {
public class LivePlayActivity extends AppCompatActivity implements ITrafficLiveCallBack {
private String TAG = "LiveActivity";
private SurfaceView surfaceView;
@@ -35,65 +34,32 @@ public class LivePlayActivity extends AppCompatActivity {
Toast.makeText(getApplicationContext(), buttonView.getText(), Toast.LENGTH_SHORT).show();
if (isChecked) {
String roomId = etLookRoomId.getText().toString().trim();
MoGoLiveManager.getInstance().init(this.getApplication(), null);
MoGoLiveManager.getInstance().loginRoom(MoGoAiCloudClientConfig.getInstance().getSn(), roomId);
MoGoLiveManager.getInstance().setLiveProgressListener(listener);
MoGoAiCloudTrafficLive.viewVehicleHeadLive(this.getApplication(), roomId, surfaceView, this);
} else {
MoGoLiveManager.getInstance().stopLive();
MoGoAiCloudTrafficLive.stopLive();
}
});
}
private ILiveProgressListener listener = new ILiveProgressListener() {
@Override
public void onConnecting() {
}
@Override
public void onConnected(String roomId) {
Log.i(TAG, "onConnected" + roomId);
isLoginSuccess = true;
toggleLive(true);
}
@Override
public void onDisConnect() {
Log.i(TAG, "onDisConnect");
isLoginSuccess = false;
toggleLive(false);
}
@Override
public void onDebugError(int errorCode, String funcName, String errorInfo) {
}
@Override
public void onRoomStreamUpdate(String streamId, boolean isLive) {
Log.i(TAG, "onRoomStreamUpdate" + streamId);
if (streamId != null && isLive) {
Toast.makeText(LivePlayActivity.this, "主播开始直播了", Toast.LENGTH_SHORT).show();
mStreamId = streamId;
} else {
Toast.makeText(LivePlayActivity.this, "主播已离线", Toast.LENGTH_SHORT).show();
}
}
};
private void toggleLive(boolean isChecked) {
if (isChecked) {
mStreamId = MoGoLiveManager.getInstance().startLive(surfaceView);
} else {
MoGoLiveManager.getInstance().stopLive();
}
Log.i(TAG, "toggleLive status : " + isChecked + " , mStreamId : " + mStreamId);
}
@Override
protected void onDestroy() {
super.onDestroy();
MoGoLiveManager.getInstance().onDestroyLive();
MoGoAiCloudTrafficLive.stopLive();
MoGoAiCloudTrafficLive.destroyLive();
}
@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);
}
}