Skip to content

Commit 2a6be1c

Browse files
committed
catch exception when open the camera device
1 parent 6a9bc4f commit 2a6be1c

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/cn/campusapp/rtmprecorder/RecordActivity.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static Intent makeIntent(String streamUrl){
8484
public void onCreate(Bundle savedInstanceState) {
8585
super.onCreate(savedInstanceState);
8686
ffmpeg_link = getIntent().getStringExtra(KEY_STREAM_URL);
87-
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
87+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
8888

8989
setContentView(R.layout.activity_record);
9090

@@ -143,8 +143,13 @@ private void initLayout() {
143143
layoutParam = new RelativeLayout.LayoutParams(prev_rw, prev_rh);
144144
layoutParam.topMargin = (int) (1.0 * bg_screen_by * screenHeight / bg_height);
145145
layoutParam.leftMargin = (int) (1.0 * bg_screen_bx * screenWidth / bg_width);
146-
147-
cameraDevice = Camera.open();
146+
try {
147+
cameraDevice = Camera.open();
148+
} catch (Exception e){
149+
Log.e(LOG_TAG, "camera open fail, if it's occupied by other applications");
150+
finish();
151+
return;
152+
}
148153
Log.i(LOG_TAG, "cameara open");
149154
cameraView = new CameraView(this, cameraDevice);
150155
topLayout.addView(cameraView, layoutParam);
@@ -383,6 +388,7 @@ public CameraView(Context context, Camera camera) {
383388
mHolder.addCallback(CameraView.this);
384389
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
385390
mCamera.setPreviewCallback(CameraView.this);
391+
mCamera.setDisplayOrientation(90);
386392
}
387393

388394
@Override

0 commit comments

Comments
 (0)