質問するログイン新規登録

質問編集履歴

3

見やすくした

2017/09/15 08:35

投稿

giant
giant

スコア132

title CHANGED
File without changes
body CHANGED
@@ -1,10 +1,6 @@
1
1
  ```java
2
2
 
3
3
 
4
- package com.google.android.exoplayer2.demo;
5
-
6
-
7
-
8
4
  public class PlayerActivity extends Activity implements OnClickListener, ExoPlayer.EventListener
9
5
  {
10
6
  //canvassは、画面にfacelineを書き込むためのやつ
@@ -39,7 +35,7 @@
39
35
  };
40
36
 
41
37
 
42
-
38
+
43
39
  private TextureView.SurfaceTextureListener mCameraSurfaceTextureListener
44
40
  = new TextureView.SurfaceTextureListener() {
45
41
 
@@ -71,7 +67,7 @@
71
67
 
72
68
  @Override
73
69
  public void onOpened(@NonNull CameraDevice cameraDevice) {
74
-
70
+
75
71
  }
76
72
  };
77
73
 
@@ -94,6 +90,8 @@
94
90
 
95
91
 
96
92
  private void startPreview() {
93
+
94
+ //多分ここの作業が足りてなかった
97
95
  try {
98
96
  SurfaceTexture texture = mTextureView.getSurfaceTexture();
99
97
  assert texture != null;
@@ -123,7 +121,39 @@
123
121
  }
124
122
  }
125
123
 
124
+ private void startPreview2() {
126
125
 
126
+ //多分ここの作業が足りてなかった
127
+ try {
128
+ SurfaceTexture texture = mCameraTextureView.getSurfaceTexture();
129
+ assert texture != null;
130
+ texture2.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
131
+ mCameraPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
132
+ Surface previewCameraSurface = new Surface(texture2);
133
+ mCameraPreviewBuilder.addTarget(previewCameraSurface);
134
+
135
+ mCameraDevice.createCaptureSession(Collections.singletonList(previewCameraSurface),
136
+ new CameraCaptureSession.StateCallback() {
137
+
138
+ @Override
139
+ public void onClosed(CameraCaptureSession session) {
140
+ }
141
+
142
+ @Override
143
+ public void onReady(CameraCaptureSession session) {
144
+ }
145
+
146
+ @Override
147
+ public void onConfigured(@NonNull CameraCaptureSession session) {
148
+ mCameraPreviewSession = session;
149
+ }
150
+
151
+ }, mBackgroundHandler);
152
+ } catch (CameraAccessException e) {
153
+ }
154
+ }
155
+
156
+
127
157
  private void startRecordingVideo() {
128
158
  if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) {
129
159
  return;
@@ -169,7 +199,7 @@
169
199
  Integer mode = result.get(CaptureResult.STATISTICS_FACE_DETECT_MODE);
170
200
  Face[] faces = result.get(CaptureResult.STATISTICS_FACES);
171
201
  if (faces != null && mode != null)
172
-
202
+
173
203
  for(Face face: faces) {
174
204
 
175
205
  Rect r=faceRect2PixelRect(face);
@@ -221,4 +251,5 @@
221
251
  }
222
252
  }
223
253
 
254
+
224
255
  ```

2

コードの編集

2017/09/15 08:35

投稿

giant
giant

スコア132

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,10 @@
1
+ ```java
2
+
3
+
4
+ package com.google.android.exoplayer2.demo;
5
+
6
+
7
+
1
8
  public class PlayerActivity extends Activity implements OnClickListener, ExoPlayer.EventListener
2
9
  {
3
10
  //canvassは、画面にfacelineを書き込むためのやつ
@@ -212,4 +219,6 @@
212
219
  r.bottom = h * (-r.right + 1000) / 2000;
213
220
  return r;
214
221
  }
215
- }
222
+ }
223
+
224
+ ```

1

コードをコンパクトにしました。

2017/09/15 08:24

投稿

giant
giant

スコア132

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,3 @@
1
- ```java
2
-
3
1
  public class PlayerActivity extends Activity implements OnClickListener, ExoPlayer.EventListener
4
2
  {
5
3
  //canvassは、画面にfacelineを書き込むためのやつ
@@ -14,7 +12,6 @@
14
12
  @Override
15
13
  public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture,
16
14
  int width, int height) {
17
- openCamera(width, height);
18
15
  }
19
16
 
20
17
  @Override
@@ -35,6 +32,7 @@
35
32
  };
36
33
 
37
34
 
35
+
38
36
  private TextureView.SurfaceTextureListener mCameraSurfaceTextureListener
39
37
  = new TextureView.SurfaceTextureListener() {
40
38
 
@@ -47,7 +45,6 @@
47
45
  public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture,
48
46
  int width, int height) {
49
47
  configureTransform(width, height);
50
-
51
48
  canvass=mCameraTextureView.lockCanvas();
52
49
  }
53
50
 
@@ -62,52 +59,34 @@
62
59
 
63
60
  };
64
61
 
65
-
62
+
66
63
  private CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
67
64
 
68
65
  @Override
69
66
  public void onOpened(@NonNull CameraDevice cameraDevice) {
70
-
71
67
 
72
- if (cameraDevice == null) {
73
-
74
- } else {
75
-
76
- if (null != mTextureView) {
77
- configureTransform(mTextureView.getWidth(), mTextureView.getHeight());
78
- }
79
- }
80
68
  }
81
69
  };
82
-
83
-
70
+
71
+
84
72
  private CaptureRequest.Builder mPreviewBuilder;
85
-
73
+
86
74
  public void onCreate(Bundle savedInstanceState) {
87
75
  super.onCreate(savedInstanceState);
88
76
 
89
77
  setContentView(R.layout.player_activity);
90
- //撮影に使うViewを取得
91
78
  mTextureView = (AutoFitTextureView) findViewById(R.id.texture);
92
79
  mCameraTextureView = (CameraFaceLineTextureView) findViewById(R.id.texture2);
93
80
 
94
81
  @Override
95
82
  public void onResume() {
96
83
  super.onResume();
97
-
98
- if (mTextureView.isAvailable()) {
99
- openCamera(mTextureView.getWidth(), mTextureView.getHeight());
100
- } else {
101
84
  mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
102
85
  mCameraTextureView.setSurfaceTextureListener(mCameraSurfaceTextureListener);
103
- }
104
86
  }
105
87
 
106
88
 
107
89
  private void startPreview() {
108
- if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) {
109
- return;
110
- }
111
90
  try {
112
91
  SurfaceTexture texture = mTextureView.getSurfaceTexture();
113
92
  assert texture != null;
@@ -134,7 +113,6 @@
134
113
 
135
114
  }, mBackgroundHandler);
136
115
  } catch (CameraAccessException e) {
137
- e.printStackTrace();
138
116
  }
139
117
  }
140
118
 
@@ -169,11 +147,9 @@
169
147
  public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
170
148
 
171
149
  mPreviewSession = cameraCaptureSession;
172
-
173
150
  }
174
151
  }, mBackgroundHandler);
175
152
  } catch (CameraAccessException | IOException e) {
176
- e.printStackTrace();
177
153
  }
178
154
 
179
155
  }
@@ -186,8 +162,7 @@
186
162
  Integer mode = result.get(CaptureResult.STATISTICS_FACE_DETECT_MODE);
187
163
  Face[] faces = result.get(CaptureResult.STATISTICS_FACES);
188
164
  if (faces != null && mode != null)
189
-
190
-
165
+
191
166
  for(Face face: faces) {
192
167
 
193
168
  Rect r=faceRect2PixelRect(face);
@@ -214,18 +189,12 @@
214
189
  public void drawFace(Rect rect1, int color) {
215
190
 
216
191
  try {
217
- if (mCameraTextureView != null) {
218
- } else if (mCameraTextureView == null) {
219
- }
220
- //直接canvassを試すからこの下のコードはいらない
221
- //Canvas canvas = mTextureView.lockCanvas();
222
192
  if (canvass != null) {
223
193
  try {
224
194
  canvass.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
225
195
  paint.setColor(color);
226
196
  canvass.drawRect(rect1,paint);
227
197
  } finally {
228
- //一応mTextureViewでやっておく
229
198
  mCameraTextureView.unlockCanvasAndPost(canvass);
230
199
  }
231
200
  }
@@ -243,5 +212,4 @@
243
212
  r.bottom = h * (-r.right + 1000) / 2000;
244
213
  return r;
245
214
  }
246
- }
215
+ }
247
- ```