Skip to content

Commit 7ef3799

Browse files
ContentResolverにビデオ情報を登録してからサムネイル情報を登録するようにした。
1 parent 503c241 commit 7ef3799

2 files changed

Lines changed: 6 additions & 16 deletions

File tree

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ void notifyEvent(final CameraEvent event) {
8080

8181
private final CameraManager mCameraManager;
8282

83-
private final HandlerThread mBackgroundThread = new HandlerThread("background");
84-
8583
private final HandlerThread mSessionConfigurationThread = new HandlerThread("session-config");
8684

8785
private final Handler mBackgroundHandler;
@@ -124,8 +122,7 @@ void notifyEvent(final CameraEvent event) {
124122
final @NonNull String cameraId) throws CameraAccessException {
125123
mCameraId = cameraId;
126124
mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
127-
mBackgroundThread.start();
128-
mBackgroundHandler = new Handler(Looper.getMainLooper());//mBackgroundThread.getLooper());
125+
mBackgroundHandler = new Handler(Looper.getMainLooper());
129126
mSessionConfigurationThread.start();
130127
mSessionConfigurationHandler = new Handler(mSessionConfigurationThread.getLooper());
131128
mOptions = initOptions();
@@ -190,7 +187,6 @@ public boolean isRecording() {
190187

191188
public synchronized void destroy() {
192189
close();
193-
mBackgroundThread.quit();
194190
mSessionConfigurationThread.quit();
195191
}
196192

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/camera/Camera2Recorder.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import java.util.List;
5656
import java.util.Locale;
5757

58+
5859
public class Camera2Recorder extends AbstractCamera2Recorder implements HostDevicePhotoRecorder, HostDeviceStreamRecorder {
5960

6061
/**
@@ -532,18 +533,15 @@ private void registerVideo(final File videoFile) {
532533
values.put(MediaStore.Video.Media.ARTIST, "DeviceConnect");
533534
values.put(MediaStore.Video.Media.MIME_TYPE, "video/avc");
534535
values.put(MediaStore.Video.Media.DATA, videoFile.toString());
535-
long thumbnailId = registerVideoThumbnail(videoFile);
536-
if (thumbnailId > -1) {
537-
values.put(MediaStore.Video.Media.MINI_THUMB_MAGIC, thumbnailId);
538-
}
539536
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
540537

541538
// 動画IDをサムネイルDBに挿入.
542539
try {
543-
if (uri != null && thumbnailId > -1) {
540+
if (uri != null) {
544541
String id = uri.getLastPathSegment();
545542
if (id != null) {
546543
long videoId = Long.parseLong(id);
544+
long thumbnailId = registerVideoThumbnail(videoFile, videoId);
547545
boolean updated = updateThumbnailInfo(thumbnailId, videoId);
548546
if (updated) {
549547
if (DEBUG) {
@@ -569,7 +567,7 @@ private void registerVideo(final File videoFile) {
569567
}
570568
}
571569

572-
private long registerVideoThumbnail(final File videoFile) {
570+
private long registerVideoThumbnail(final File videoFile, final long videoId) {
573571
String videoFilePath = videoFile.getAbsolutePath();
574572
final int kind = MediaStore.Images.Thumbnails.MINI_KIND;
575573
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(videoFilePath, kind);
@@ -588,6 +586,7 @@ private long registerVideoThumbnail(final File videoFile) {
588586
values.put(MediaStore.Video.Thumbnails.WIDTH, thumbnail.getWidth());
589587
values.put(MediaStore.Video.Thumbnails.HEIGHT, thumbnail.getHeight());
590588
values.put(MediaStore.Video.Thumbnails.KIND, kind);
589+
values.put(MediaStore.Video.Thumbnails.VIDEO_ID, videoId);
591590
ContentResolver resolver = getContext().getApplicationContext().getContentResolver();
592591
Uri uri = resolver.insert(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, values);
593592
if (uri == null) {
@@ -617,11 +616,6 @@ private long registerVideoThumbnail(final File videoFile) {
617616
Log.e(TAG, "Failed to parse thumbnail ID as long type: videoFilePath=" + videoFilePath);
618617
}
619618
return -1;
620-
} catch (NullPointerException e) {
621-
if (DEBUG) {
622-
Log.e(TAG, "Failed to parse thumbnail ID as long type: videoFilePath=" + videoFilePath);
623-
}
624-
return -1;
625619
} finally {
626620
thumbnail.recycle();
627621
}

0 commit comments

Comments
 (0)