|
4 | 4 | import android.app.Activity;
|
5 | 5 | import android.app.Fragment;
|
6 | 6 | import android.app.FragmentTransaction;
|
7 |
| -import android.content.ContentResolver; |
8 | 7 | import android.content.ContentValues;
|
9 | 8 | import android.content.Context;
|
10 | 9 | import android.content.Intent;
|
|
14 | 13 | import android.media.AudioDeviceInfo;
|
15 | 14 | import android.media.projection.MediaProjection;
|
16 | 15 | import android.media.projection.MediaProjectionManager;
|
17 |
| -import android.net.Uri; |
18 | 16 | import android.os.Build;
|
19 | 17 | import android.os.Build.VERSION;
|
20 | 18 | import android.os.Build.VERSION_CODES;
|
21 | 19 | import android.os.Bundle;
|
22 | 20 | import android.os.Handler;
|
23 | 21 | import android.os.Looper;
|
24 |
| -import android.os.ParcelFileDescriptor; |
25 | 22 | import android.os.ResultReceiver;
|
26 | 23 | import android.provider.MediaStore;
|
27 | 24 | import android.util.Log;
|
|
72 | 69 | import org.webrtc.audio.JavaAudioDeviceModule;
|
73 | 70 |
|
74 | 71 | import java.io.File;
|
75 |
| -import java.io.FileInputStream; |
76 |
| -import java.io.FileOutputStream; |
77 |
| -import java.io.InputStream; |
78 | 72 | import java.util.ArrayList;
|
79 | 73 | import java.util.HashMap;
|
80 | 74 | import java.util.List;
|
@@ -969,64 +963,22 @@ void startRecordingToFile(
|
969 | 963 | mediaRecorders.append(id, mediaRecorder);
|
970 | 964 | }
|
971 | 965 |
|
972 |
| - void stopRecording(Integer id, String albumName) { |
973 |
| - try { |
974 |
| - MediaRecorderImpl mediaRecorder = mediaRecorders.get(id); |
975 |
| -
628C
if (mediaRecorder != null) { |
976 |
| - mediaRecorder.stopRecording(); |
977 |
| - mediaRecorders.remove(id); |
978 |
| - File file = mediaRecorder.getRecordFile(); |
979 |
| - Uri collection; |
980 |
| - |
981 |
| - if (file != null) { |
982 |
| - ContentValues values = new ContentValues(); |
983 |
| - values.put(MediaStore.Video.Media.TITLE, file.getName()); |
984 |
| - values.put(MediaStore.Video.Media.DISPLAY_NAME, file.getName()); |
985 |
| - values.put(MediaStore.Video.Media.ALBUM, albumName); |
986 |
| - values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4"); |
987 |
| - values.put(MediaStore.Video.Media.DATE_ADDED, System.currentTimeMillis() / 1000); |
988 |
| - values.put(MediaStore.Video.Media.DATE_TAKEN, System.currentTimeMillis()); |
989 |
| - |
990 |
| - //Android version above 9 MediaStore uses RELATIVE_PATH |
991 |
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
992 |
| - values.put(MediaStore.Video.Media.RELATIVE_PATH, "Movies/" + albumName); |
993 |
| - values.put(MediaStore.Video.Media.IS_PENDING, 1); |
994 |
| - |
995 |
| - collection = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY); |
996 |
| - } else { |
997 |
| - //Android version 9 and below MediaStore uses DATA |
998 |
| - values.put(MediaStore.Video.Media.DATA, "/storage/emulated/0/Movies/" + albumName + "/" + file.getName()); |
999 |
| - |
1000 |
| - collection = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; |
1001 |
| - } |
1002 |
| - |
1003 |
| - ContentResolver resolver = applicationContext.getContentResolver(); |
1004 |
| - Uri uriSavedMedia = resolver.insert(collection, values); |
1005 |
| - |
1006 |
| - assert uriSavedMedia != null; |
1007 |
| - ParcelFileDescriptor pfd = resolver.openFileDescriptor(uriSavedMedia, "w"); |
1008 |
| - assert pfd != null; |
1009 |
| - FileOutputStream out = new FileOutputStream(pfd.getFileDescriptor()); |
1010 |
| - |
1011 |
| - InputStream in = new FileInputStream(file); |
1012 |
| - |
1013 |
| - byte[] buf = new byte[8192]; |
1014 |
| - int len; |
1015 |
| - |
1016 |
| - while ((len = in.read(buf)) > 0) { |
1017 |
| - out.write(buf, 0, len); |
1018 |
| - } |
1019 |
| - |
1020 |
| - out.close(); |
1021 |
| - in.close(); |
1022 |
| - pfd.close(); |
1023 |
| - values.clear(); |
1024 |
| - } |
| 966 | + void stopRecording(Integer id) { |
| 967 | + MediaRecorderImpl mediaRecorder = mediaRecorders.get(id); |
| 968 | + if (mediaRecorder != null) { |
| 969 | + mediaRecorder.stopRecording(); |
| 970 | + mediaRecorders.remove(id); |
| 971 | + File file = mediaRecorder.getRecordFile(); |
| 972 | + if (file != null) { |
| 973 | + ContentValues values = new ContentValues(3); |
| 974 | + values.put(MediaStore.Video.Media.TITLE, file.getName()); |
| 975 | + values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4"); |
| 976 | + values.put(MediaStore.Video.Media.DATA, file.getAbsolutePath()); |
| 977 | + applicationContext |
| 978 | + .getContentResolver() |
| 979 | + .insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values); |
1025 | 980 | }
|
1026 |
| - } catch(Exception e){ |
1027 |
| - |
1028 | 981 | }
|
1029 |
| - |
1030 | 982 | }
|
1031 | 983 |
|
1032 | 984 |
|
|
0 commit comments