Skip to content

Commit a1dfe7a

Browse files
LiveStreamingプロファイル実行時のカメラパーミッションの取得
## 修正内容 * LiveStreamingプロファイル実行時にカメラのパーミッションを取得するようにした。
1 parent 6e18fbc commit a1dfe7a

1 file changed

Lines changed: 117 additions & 54 deletions

File tree

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLiveStreamingProfile.java

Lines changed: 117 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -132,56 +132,68 @@ public boolean onRequest(final Intent request, final Intent response) {
132132
MessageUtils.setUnknownError(response, ex.getMessage());
133133
return true;
134134
}
135-
136-
//クライアントの生成
137-
mHostDeviceLiveStreamRecorder.createLiveStreamingClient(broadcastURI, eventListener);
138-
139-
//映像無し以外の場合はエンコーダーとパラメーターをセット
140-
if (!mVideoURI.equals("false")) {
141-
Integer width = parseInteger(request, PARAM_KEY_WIDTH);
142-
Integer height = parseInteger(request, PARAM_KEY_HEIGHT);
143-
Integer bitrate = parseInteger(request, PARAM_KEY_BITRATE);
144-
Integer frameRate = parseInteger(request, PARAM_KEY_FRAME_RATE);
145-
if (DEBUG) {
146-
Log.d(TAG, "width : " + width);
147-
Log.d(TAG, "height : " + height);
148-
Log.d(TAG, "bitrate : " + bitrate);
149-
Log.d(TAG, "frameRate : " + frameRate);
135+
((HostMediaRecorder) mHostDeviceLiveStreamRecorder).requestPermission(new HostMediaRecorder.PermissionCallback() {
136+
@Override
137+
public void onAllowed() {
138+
//クライアントの生成
139+
mHostDeviceLiveStreamRecorder.createLiveStreamingClient(broadcastURI, eventListener);
140+
141+
//映像無し以外の場合はエンコーダーとパラメーターをセット
142+
if (!mVideoURI.equals("false")) {
143+
Integer width = parseInteger(request, PARAM_KEY_WIDTH);
144+
Integer height = parseInteger(request, PARAM_KEY_HEIGHT);
145+
Integer bitrate = parseInteger(request, PARAM_KEY_BITRATE);
146+
Integer frameRate = parseInteger(request, PARAM_KEY_FRAME_RATE);
147+
if (DEBUG) {
148+
Log.d(TAG, "width : " + width);
149+
Log.d(TAG, "height : " + height);
150+
Log.d(TAG, "bitrate : " + bitrate);
151+
Log.d(TAG, "frameRate : " + frameRate);
152+
}
153+
mHostDeviceLiveStreamRecorder.setVideoEncoder(width, height, bitrate, frameRate);
154+
}
155+
156+
//音声リソースURIの取得
157+
mAudioURI = (String) extras.get(PARAM_KEY_AUDIO);
158+
if (mAudioURI == null) {
159+
mAudioURI = "false";
160+
} else {
161+
switch (mAudioURI) {
162+
case AUDIO_URI_TRUE:
163+
case AUDIO_URI_FALSE:
164+
break;
165+
default:
166+
MessageUtils.setInvalidRequestParameterError(response, "audio parameter illegal");
167+
sendResponse(response);
168+
return;
169+
}
170+
}
171+
if (DEBUG) {
172+
Log.d(TAG, "audioUri : " + mAudioURI);
173+
}
174+
175+
//音声無し以外の場合はエンコーダーをセット
176+
if (!mAudioURI.equals("false")) {
177+
mHostDeviceLiveStreamRecorder.setAudioEncoder();
178+
}
179+
180+
//ストリーミング開始
181+
mHostDeviceLiveStreamRecorder.startLiveStreaming();
182+
183+
setResult(response, DConnectMessage.RESULT_OK);
184+
sendResponse(response);
150185
}
151-
mHostDeviceLiveStreamRecorder.setVideoEncoder(width, height, bitrate, frameRate);
152-
}
153186

154-
//音声リソースURIの取得
155-
mAudioURI = (String) extras.get(PARAM_KEY_AUDIO);
156-
if (mAudioURI == null) {
157-
mAudioURI = "false";
158-
} else {
159-
switch (mAudioURI) {
160-
case AUDIO_URI_TRUE:
161-
case AUDIO_URI_FALSE:
162-
break;
163-
default:
164-
MessageUtils.setInvalidRequestParameterError(response, "audio parameter illegal");
165-
return true;
187+
@Override
188+
public void onDisallowed() {
189+
MessageUtils.setUnknownError(response, "Permission for camera is not granted.");
190+
sendResponse(response);
166191
}
167-
}
168-
if (DEBUG) {
169-
Log.d(TAG, "audioUri : " + mAudioURI);
170-
}
171-
172-
//音声無し以外の場合はエンコーダーをセット
173-
if (!mAudioURI.equals("false")) {
174-
mHostDeviceLiveStreamRecorder.setAudioEncoder();
175-
}
176-
177-
//ストリーミング開始
178-
mHostDeviceLiveStreamRecorder.startLiveStreaming();
179-
180-
setResult(response, DConnectMessage.RESULT_OK);
192+
});
193+
return false;
181194
} else {
182195
MessageUtils.setInvalidRequestParameterError(response, "parameter not available");
183196
}
184-
185197
return true;
186198
}
187199
});
@@ -203,10 +215,26 @@ public boolean onRequest(final Intent request, final Intent response) {
203215
MessageUtils.setIllegalDeviceStateError(response, "status is not normal(streaming)");
204216
return true;
205217
}
206-
mHostDeviceLiveStreamRecorder.stopLiveStreaming();
218+
((HostMediaRecorder) mHostDeviceLiveStreamRecorder)
219+
.requestPermission(new HostMediaRecorder.PermissionCallback() {
220+
@Override
221+
public void onAllowed() {
222+
mHostDeviceLiveStreamRecorder.stopLiveStreaming();
223+
setResult(response, DConnectMessage.RESULT_OK);
224+
sendResponse(response);
225+
}
226+
227+
@Override
228+
public void onDisallowed() {
229+
MessageUtils.setUnknownError(response, "Permission for camera is not granted.");
230+
sendResponse(response);
231+
}
232+
});
233+
return false;
234+
} else {
235+
MessageUtils.setIllegalDeviceStateError(response, "status is not normal(streaming)");
236+
return true;
207237
}
208-
setResult(response, DConnectMessage.RESULT_OK);
209-
return true;
210238
}
211239
});
212240

@@ -309,11 +337,28 @@ public boolean onRequest(final Intent request, final Intent response) {
309337
if (DEBUG) {
310338
Log.d(TAG, "onRequest() : put /mute");
311339
}
340+
312341
if (mHostDeviceLiveStreamRecorder != null) {
313-
mHostDeviceLiveStreamRecorder.setMute(true);
342+
((HostMediaRecorder) mHostDeviceLiveStreamRecorder)
343+
.requestPermission(new HostMediaRecorder.PermissionCallback() {
344+
@Override
345+
public void onAllowed() {
346+
mHostDeviceLiveStreamRecorder.setMute(true);
347+
setResult(response, DConnectMessage.RESULT_OK);
348+
sendResponse(response);
349+
}
350+
351+
@Override
352+
public void onDisallowed() {
353+
MessageUtils.setUnknownError(response, "Permission for camera is not granted.");
354+
sendResponse(response);
355+
}
356+
});
357+
return false;
358+
} else {
359+
MessageUtils.setIllegalDeviceStateError(response, "status is not normal(streaming)");
360+
return true;
314361
}
315-
setResult(response, DConnectMessage.RESULT_OK);
316-
return true;
317362
}
318363
});
319364

@@ -329,10 +374,26 @@ public boolean onRequest(final Intent request, final Intent response) {
329374
Log.d(TAG, "onRequest() : delete /mute");
330375
}
331376
if (mHostDeviceLiveStreamRecorder != null) {
332-
mHostDeviceLiveStreamRecorder.setMute(false);
377+
((HostMediaRecorder) mHostDeviceLiveStreamRecorder)
378+
.requestPermission(new HostMediaRecorder.PermissionCallback() {
379+
@Override
380+
public void onAllowed() {
381+
mHostDeviceLiveStreamRecorder.setMute(false);
382+
setResult(response, DConnectMessage.RESULT_OK);
383+
sendResponse(response);
384+
}
385+
386+
@Override
387+
public void onDisallowed() {
388+
MessageUtils.setUnknownError(response, "Permission for camera is not granted.");
389+
sendResponse(response);
390+
}
391+
});
392+
return false;
393+
} else {
394+
MessageUtils.setIllegalDeviceStateError(response, "status is not normal(streaming)");
395+
return true;
333396
}
334-
setResult(response, DConnectMessage.RESULT_OK);
335-
return true;
336397
}
337398
});
338399

@@ -346,8 +407,10 @@ public String getAttribute() {
346407
public boolean onRequest(final Intent request, final Intent response) {
347408
if (mHostDeviceLiveStreamRecorder != null) {
348409
response.putExtra(PARAM_KEY_MUTE, mHostDeviceLiveStreamRecorder.isMute());
410+
setResult(response, DConnectMessage.RESULT_OK);
411+
} else {
412+
MessageUtils.setIllegalDeviceStateError(response, "status is not normal(streaming)");
349413
}
350-
setResult(response, DConnectMessage.RESULT_OK);
351414
return true;
352415
}
353416
});

0 commit comments

Comments
 (0)