diff options
| author | 2020-06-05 14:12:32 +0000 | |
|---|---|---|
| committer | 2020-06-05 14:12:32 +0000 | |
| commit | 032c292e74d356403c00cf433d0f416d80d15863 (patch) | |
| tree | c0325f57cb1b6d29e1fbb298d6b3acaafbc702ed | |
| parent | c9f8b52b26a29bafc3470a581cfcaa787dce063c (diff) | |
| parent | 57e2aa4de6187946e9d18f91ce9eeddcc2f92f9b (diff) | |
Merge "Improve screen recording thumbnail image" into rvc-dev
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java | 16 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java | 44 |
2 files changed, 44 insertions, 16 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java index 3e268f63d65e..2ddd6aaf4c40 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java @@ -33,9 +33,7 @@ import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; import android.provider.Settings; -import android.util.DisplayMetrics; import android.util.Log; -import android.util.Size; import android.widget.Toast; import com.android.systemui.R; @@ -247,7 +245,8 @@ public class RecordingService extends Service implements MediaRecorder.OnInfoLis startForeground(NOTIFICATION_RECORDING_ID, notification); } - private Notification createSaveNotification(Uri uri) { + private Notification createSaveNotification(ScreenMediaRecorder.SavedRecording recording) { + Uri uri = recording.getUri(); Intent viewIntent = new Intent(Intent.ACTION_VIEW) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION) .setDataAndType(uri, "video/mp4"); @@ -290,16 +289,7 @@ public class RecordingService extends Service implements MediaRecorder.OnInfoLis .addExtras(extras); // Add thumbnail if available - Bitmap thumbnailBitmap = null; - try { - ContentResolver resolver = getContentResolver(); - DisplayMetrics metrics = getResources().getDisplayMetrics(); - Size size = new Size(metrics.widthPixels, metrics.heightPixels / 2); - thumbnailBitmap = resolver.loadThumbnail(uri, size, null); - } catch (IOException e) { - Log.e(TAG, "Error creating thumbnail: " + e.getMessage()); - e.printStackTrace(); - } + Bitmap thumbnailBitmap = recording.getThumbnail(); if (thumbnailBitmap != null) { Notification.BigPictureStyle pictureStyle = new Notification.BigPictureStyle() .bigPicture(thumbnailBitmap) diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java index 8551c88d133a..1c7d987afff2 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java @@ -22,13 +22,17 @@ import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.INTER import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.MIC; import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.MIC_AND_INTERNAL; +import android.annotation.Nullable; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; +import android.graphics.Bitmap; import android.hardware.display.DisplayManager; import android.hardware.display.VirtualDisplay; +import android.media.MediaCodecInfo; import android.media.MediaMuxer; import android.media.MediaRecorder; +import android.media.ThumbnailUtils; import android.media.projection.IMediaProjection; import android.media.projection.IMediaProjectionManager; import android.media.projection.MediaProjection; @@ -40,6 +44,7 @@ import android.os.ServiceManager; import android.provider.MediaStore; import android.util.DisplayMetrics; import android.util.Log; +import android.util.Size; import android.view.Surface; import android.view.WindowManager; @@ -125,6 +130,9 @@ public class ScreenMediaRecorder { int vidBitRate = screenHeight * screenWidth * refereshRate / VIDEO_FRAME_RATE * VIDEO_FRAME_RATE_TO_RESOLUTION_RATIO; mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); + mMediaRecorder.setVideoEncodingProfileLevel( + MediaCodecInfo.CodecProfileLevel.AVCProfileHigh, + MediaCodecInfo.CodecProfileLevel.AVCLevel42); mMediaRecorder.setVideoSize(screenWidth, screenHeight); mMediaRecorder.setVideoFrameRate(refereshRate); mMediaRecorder.setVideoEncodingBitRate(vidBitRate); @@ -206,7 +214,7 @@ public class ScreenMediaRecorder { /** * Store recorded video */ - Uri save() throws IOException { + protected SavedRecording save() throws IOException { String fileName = new SimpleDateFormat("'screen-'yyyyMMdd-HHmmss'.mp4'") .format(new Date()); @@ -244,8 +252,38 @@ public class ScreenMediaRecorder { OutputStream os = resolver.openOutputStream(itemUri, "w"); Files.copy(mTempVideoFile.toPath(), os); os.close(); - mTempVideoFile.delete(); if (mTempAudioFile != null) mTempAudioFile.delete(); - return itemUri; + DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); + Size size = new Size(metrics.widthPixels, metrics.heightPixels); + SavedRecording recording = new SavedRecording(itemUri, mTempVideoFile, size); + mTempVideoFile.delete(); + return recording; + } + + /** + * Object representing the recording + */ + public class SavedRecording { + + private Uri mUri; + private Bitmap mThumbnailBitmap; + + protected SavedRecording(Uri uri, File file, Size thumbnailSize) { + mUri = uri; + try { + mThumbnailBitmap = ThumbnailUtils.createVideoThumbnail( + file, thumbnailSize, null); + } catch (IOException e) { + Log.e(TAG, "Error creating thumbnail", e); + } + } + + public Uri getUri() { + return mUri; + } + + public @Nullable Bitmap getThumbnail() { + return mThumbnailBitmap; + } } } |