|
|
@@ -1,118 +0,0 @@
|
|
|
-package com.qingdaofushan.home.activity;
|
|
|
-
|
|
|
-import androidx.appcompat.app.AppCompatActivity;
|
|
|
-
|
|
|
-import android.Manifest;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.text.TextUtils;
|
|
|
-import android.view.View;
|
|
|
-import android.widget.RelativeLayout;
|
|
|
-
|
|
|
-import com.qingdaofushan.home.event.EventData;
|
|
|
-import com.qingdaofushan.home.R;
|
|
|
-import com.qingdaofushan.home.utils.ToastUtil;
|
|
|
-
|
|
|
-import org.greenrobot.eventbus.EventBus;
|
|
|
-
|
|
|
-import io.reactivex.Observable;
|
|
|
-import me.lake.librestreaming.core.listener.RESConnectionListener;
|
|
|
-import me.lake.librestreaming.ws.StreamAVOption;
|
|
|
-import me.lake.librestreaming.ws.StreamLiveCameraView;
|
|
|
-
|
|
|
-public class LiveActivity extends AppCompatActivity implements View.OnClickListener {
|
|
|
-
|
|
|
- private StreamLiveCameraView mLiveCameraView;
|
|
|
- private StreamAVOption streamAVOption;
|
|
|
- private String rtmpUrl = "rtmp://blsspush.qingdaofushan.com/fushan/888888";
|
|
|
- private RelativeLayout rl_suspend;
|
|
|
- private RelativeLayout rl_stop;
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_live);
|
|
|
- initView();
|
|
|
- rtmpUrl = getIntent().getStringExtra("url");
|
|
|
- if (TextUtils.isEmpty(rtmpUrl)) {
|
|
|
- ToastUtil.showToast("推流地址有误");
|
|
|
- finish();
|
|
|
- return;
|
|
|
- }
|
|
|
- initLiveConfig();
|
|
|
- if (!mLiveCameraView.isStreaming()) {
|
|
|
- mLiveCameraView.startStreaming(rtmpUrl);
|
|
|
- }
|
|
|
- findViewById(R.id.tv_stop).setOnClickListener(view -> {
|
|
|
-
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private void initView() {
|
|
|
- rl_suspend = findViewById(R.id.rl_suspend);
|
|
|
- rl_stop = findViewById(R.id.rl_stop);
|
|
|
- rl_suspend.setOnClickListener(this);
|
|
|
- rl_stop.setOnClickListener(this);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- if (R.id.rl_suspend == v.getId()) {
|
|
|
- //暂停
|
|
|
- if (mLiveCameraView.isStreaming()) {
|
|
|
- mLiveCameraView.stopStreaming();
|
|
|
- }
|
|
|
- EventBus.getDefault().post(new EventData(2));
|
|
|
- finish();
|
|
|
- } else if (R.id.rl_stop == v.getId()) {
|
|
|
- //停止
|
|
|
- if (mLiveCameraView.isStreaming()) {
|
|
|
- mLiveCameraView.stopStreaming();
|
|
|
- }
|
|
|
- EventBus.getDefault().post(new EventData(1));
|
|
|
- finish();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置推流参数
|
|
|
- */
|
|
|
- public void initLiveConfig() {
|
|
|
- mLiveCameraView = findViewById(R.id.stream_previewView);
|
|
|
-
|
|
|
- //参数配置 start
|
|
|
- streamAVOption = new StreamAVOption();
|
|
|
- streamAVOption.streamUrl = rtmpUrl;
|
|
|
- //参数配置 end
|
|
|
-
|
|
|
- mLiveCameraView.init(this, streamAVOption);
|
|
|
- mLiveCameraView.addStreamStateListener(resConnectionListener);
|
|
|
- }
|
|
|
-
|
|
|
- RESConnectionListener resConnectionListener = new RESConnectionListener() {
|
|
|
- @Override
|
|
|
- public void onOpenConnectionResult(int result) {
|
|
|
- //result 0成功 1 失败
|
|
|
- ToastUtil.showToast("打开推流连接 状态:" + result + " 推流地址:" + rtmpUrl);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onWriteError(int errno) {
|
|
|
- ToastUtil.showToast("推流出错,请尝试重连");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCloseConnectionResult(int result) {
|
|
|
- ToastUtil.showToast("关闭推流连接 状态:" + result);
|
|
|
- //result 0成功 1 失败
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onDestroy() {
|
|
|
- super.onDestroy();
|
|
|
- mLiveCameraView.destroy();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|