记录一个SurfeceView
我正在使用第 3 方library,这个库需要一个路径,在我的例子中保存的输出(录制的视频)是保存的视频路径 :
mRenderPipeline = EZFilter.input(this.effectBmp)
.addFilter(new Effects().getEffect(VideoMaker.this, i))
.enableRecord(savedVideoPath, true, false)
.into(mRenderView);
录制停止后,视频应保存为保存的视频路径作为一条路径,当我测试代码时,也就是说,当我打开图库应用程序时,我可以看到那里保存的视频,但是当我在Android Q上测试时,我看不到任何东西。
Since getExternalStoragePublicDirectory
and getExternalStorageDirectory
已弃用,我尝试使用getExternalFilesDir
如下:
private void getPath() {
String videoFileName = "video_" + System.currentTimeMillis() + ".mp4";
fileName = videoFileName;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
File imageFile = null;
File storageDir = new File(
getExternalFilesDir(Environment.DIRECTORY_MOVIES),
"Folder");
source = storageDir;
boolean success = true;
if (!storageDir.exists()) {
success = storageDir.mkdirs();
}
if (success) {
imageFile = new File(storageDir, videoFileName);
savedVideoPath = imageFile.getAbsolutePath();
}
} else {
File storageDir = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
+ "/Folder");
boolean success = true;
if (!storageDir.exists()) {
success = storageDir.mkdirs();
}
if (success) {
File videoFile = new File(storageDir, videoFileName);
savedVideoPath = videoFile.getAbsolutePath();
}
}
}
录音停止后,我转到文件资源管理器应用程序 > Android > 数据 > com.packageName > 文件 > 电影 > 文件夹,我可以在那里看到所有保存的视频,但在图库中看不到它们。
我尝试使用Intent.ACTION_MEDIA_SCANNER_SCAN_FILE
刷新画廊,但不幸的是不起作用。
我也尝试过MediaScannerConnection
:
MediaScannerConnection.scanFile(
context,
new String[]{savedVideoPath},
new String[]{"video/mp4"},
new MediaScannerConnection.MediaScannerConnectionClient() {
public void onMediaScannerConnected() {
}
public void onScanCompleted(String s, Uri uri) {
}
});