|
|
|
@ -40,7 +40,7 @@ import java.util.Random;
|
|
|
|
|
public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpListener,
|
|
|
|
|
SrsRecordHandler.SrsRecordListener, SrsEncodeHandler.SrsEncodeListener {
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "Yasea";
|
|
|
|
|
private static final String TAG = "MpLive";
|
|
|
|
|
public final static int RC_CAMERA = 100;
|
|
|
|
|
|
|
|
|
|
private Button btnPublish;
|
|
|
|
@ -92,7 +92,11 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
|
|
|
|
|
}else{
|
|
|
|
|
//权限已经开启,做相应事情
|
|
|
|
|
isPermissionGranted = true;
|
|
|
|
|
init();
|
|
|
|
|
try {
|
|
|
|
|
init();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -104,7 +108,11 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
|
|
|
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
//权限被用户同意,做相应的事情
|
|
|
|
|
isPermissionGranted = true;
|
|
|
|
|
init();
|
|
|
|
|
try {
|
|
|
|
|
init();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//权限被用户拒绝,做相应的事情
|
|
|
|
|
finish();
|
|
|
|
@ -114,7 +122,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
|
|
|
|
|
|
|
|
|
|
private void init() {
|
|
|
|
|
// restore data.
|
|
|
|
|
sp = getSharedPreferences("Yasea", MODE_PRIVATE);
|
|
|
|
|
sp = getSharedPreferences("MpLive", MODE_PRIVATE);
|
|
|
|
|
rtmpUrl = sp.getString("rtmpUrl", rtmpUrl);
|
|
|
|
|
|
|
|
|
|
// initialize url.
|
|
|
|
@ -138,9 +146,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
|
|
|
|
|
|
|
|
|
|
mPublisher = new SrsPublisher(mCameraView);
|
|
|
|
|
|
|
|
|
|
if (intent.hasExtra("cameraId")) {
|
|
|
|
|
mPublisher.switchCameraFace(intent.getIntExtra("cameraId", 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String url = intent.getStringExtra("url");
|
|
|
|
|
if (!TextUtils.isEmpty(url)) {
|
|
|
|
@ -153,9 +159,12 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
|
|
|
|
|
mPublisher.setPreviewResolution(mWidth, mHeight);
|
|
|
|
|
mPublisher.setOutputResolution(mHeight, mWidth); // 这里要和preview反过来
|
|
|
|
|
mPublisher.setVideoHDMode();
|
|
|
|
|
if (intent.hasExtra("cameraId")) {
|
|
|
|
|
int cameraId = intent.getIntExtra("cameraId", 0);
|
|
|
|
|
mPublisher.switchCameraFace(cameraId);
|
|
|
|
|
}
|
|
|
|
|
mPublisher.startCamera();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mCameraView.setCameraCallbacksHandler(new SrsCameraView.CameraCallbacksHandler(){
|
|
|
|
|
@Override
|
|
|
|
|
public void onCameraParameters(Camera.Parameters params) {
|
|
|
|
@ -180,6 +189,7 @@ public class MainActivity extends AppCompatActivity implements RtmpHandler.RtmpL
|
|
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
Log.w(TAG, "Close self automatically");
|
|
|
|
|
finish();
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|