Skip to content

Commit

Permalink
Fix camera surface view binding
Browse files Browse the repository at this point in the history
Surface view will be destroyed on pause and should be reset to camara on
resume.

Signed-off-by: Leo Ma <[email protected]>
  • Loading branch information
begeekmyfriend committed Jun 4, 2016
1 parent 15247e9 commit 9607b4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 7 additions & 1 deletion app/src/main/java/net/ossrs/yasea/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ protected void onCreate(Bundle savedInstanceState) {
btnRecord = (Button) findViewById(R.id.record);
mCameraView = (SurfaceView) findViewById(R.id.preview);
mCameraView.getHolder().addCallback(this);
// mCameraView.getHolder().setFormat(SurfaceHolder.SURFACE_TYPE_HARDWARE);

btnPublish.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -477,6 +476,13 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width, int heig
@Override
public void surfaceCreated(SurfaceHolder arg0) {
Log.d(TAG, "surfaceCreated");
if (mCamera != null) {
try {
mCamera.setPreviewDisplay(mCameraView.getHolder());
} catch (IOException e) {
e.printStackTrace();
}
}
}

@Override
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="net.ossrs.yasea.MainActivity">

<SurfaceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/preview" />
android:id="@+id/preview"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<Button
android:layout_width="wrap_content"
Expand Down

0 comments on commit 9607b4f

Please sign in to comment.