rtsp适配控制

nx_mplive
liuguijing 4 weeks ago
parent 55cab57cdc
commit 7c2b5e0911

@ -56,8 +56,6 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
private Button btnPause;
private SharedPreferences sp;
// private String rtmpUrl = "rtmp://192.168.50.250/live/0";
// private String rtmpUrl = "rtmp://61.169.135.146/live/0";
private String rtmpUrl = "rtmp://127.0.0.1/live/0";
private String recPath = Environment.getExternalStorageDirectory().getPath() + "/test.mp4";
@ -131,18 +129,12 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
}
private void init() {
Intent intent = getIntent();
final int autoStart = intent.getIntExtra("autoStart", 1);
final int autoStart = intent.getIntExtra("autoStart", 1);// 1--代表只开启rtmpserver 2--代表开启rtmpserver同时打开摄像头推流 其他状态表示只开启摄像头
// restore data.
sp = getSharedPreferences("MpLive", MODE_PRIVATE);
// rtmpUrl = sp.getString("rtmpUrl", rtmpUrl);
// initialize url.
final EditText efu = (EditText) findViewById(R.id.url);
btnPublish = (Button) findViewById(R.id.publish);
btnSwitchCamera = (Button) findViewById(R.id.swCam);
btnRecord = (Button) findViewById(R.id.record);
@ -154,7 +146,6 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
if (!TextUtils.isEmpty(url)) {
rtmpUrl = url;
}
if (TextUtils.isEmpty(rtmpUrl)) {
rtmpUrl = "rtmp://127.0.0.1/live/0";
}
@ -180,9 +171,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
mPublisher.setVideoHDMode();
cameraId = intent.getIntExtra("cameraId", 0);
// mPublisher.startCamera();
mCameraView.setCameraCallbacksHandler(new SrsCameraView.CameraCallbacksHandler() {
@Override
@ -191,32 +180,30 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
}
});
if (autoStart != 0) {
if (autoStart == 1) {
startRTMPServer();
// mHandler.postDelayed(new Runnable() {
// @Override
// public void run() {
//// rtmpUrl = "rtmp://61.169.135.146/live/0";
// SharedPreferences.Editor editor = sp.edit();
// editor.putString("rtmpUrl", rtmpUrl);
// editor.apply();
// efu.setText(rtmpUrl + "rotation= " + rotation + " cameraid=" + cameraId + " auto=" + autoStart);
// // efu.setText(rtmpUrl + " cameraid=" + cameraId + " auto=" + autoStart);
// efu.setText(rtmpUrl);
// mPublisher.startPublish(rtmpUrl);
// if (btnSwitchEncoder.getText().toString().contentEquals("soft encoder")) {
// // Toast.makeText(getApplicationContext(), "Use hard encoder", Toast.LENGTH_SHORT).show();
// } else {
// Toast.makeText(getApplicationContext(), "Use soft encoder", Toast.LENGTH_SHORT).show();
// }
// btnPublish.setText("stop");
// btnSwitchEncoder.setEnabled(false);
// btnPause.setEnabled(true);
// mPublisher.switchCameraFace(cameraId, rotation);
// }
// }, 500);
} else if (autoStart == 2) {
startRTMPServer();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
SharedPreferences.Editor editor = sp.edit();
editor.putString("rtmpUrl", rtmpUrl);
editor.apply();
efu.setText(rtmpUrl + "rotation= " + rotation + " cameraid=" + cameraId + " auto=" + autoStart);
efu.setText(rtmpUrl);
mPublisher.startPublish(rtmpUrl);
if (btnSwitchEncoder.getText().toString().contentEquals("soft encoder")) {
// Toast.makeText(getApplicationContext(), "Use hard encoder", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Use soft encoder", Toast.LENGTH_SHORT).show();
}
btnPublish.setText("stop");
btnSwitchEncoder.setEnabled(false);
btnPause.setEnabled(true);
mPublisher.switchCameraFace(cameraId, rotation);
}
}, 500);
} else {
mPublisher.switchCameraFace(cameraId, rotation);
}
@ -230,7 +217,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
finish();
System.exit(0);
}
}, 1000);
}, 100000);
}
btnPublish.setOnClickListener(new View.OnClickListener() {
@ -247,7 +234,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
efu.setText(rtmpUrl);
mPublisher.startPublish(rtmpUrl);
// mPublisher.startCamera();
mPublisher.switchCameraFace(cameraId,rotation);
mPublisher.switchCameraFace(cameraId, rotation);
if (btnSwitchEncoder.getText().toString().contentEquals("soft encoder")) {
Toast.makeText(getApplicationContext(), "Use hard encoder", Toast.LENGTH_SHORT).show();
@ -286,7 +273,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
int size = cameraData.size();
if (size > 0) {
int i = (++cameraId) % size;
mPublisher.switchCameraFace(cameraId,rotation);
mPublisher.switchCameraFace(cameraId, rotation);
}
}
});
@ -452,10 +439,10 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
try {
inputStream = getAssets().open("config.ini");
fos = new FileOutputStream(confFile);
int len=-1;
int len = -1;
byte[] buffer = new byte[1024];
while ((len=inputStream.read(buffer)) != -1) {
fos.write(buffer,0, len);
while ((len = inputStream.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.flush();
} catch (Exception e) {

Loading…
Cancel
Save