我们正尝试在我们的某个应用程序中使用MediaStore.ACTION_VIDEO_CAPTURE录制视频。 该文件需要保存在内部存储中,我们正在授予权限运行时。
问题是视频被录制并保存在提供的uri中,但是在尝试播放预览时,很少有设备说视频无法播放,但视频实际上是在路径中录制的。
以下是我的代码。
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null)
{
// Let's get rid of the my-moments screen because it will free up some memory for post capture screen
String videoPath = UUID.randomUUID().toString() + ".mp4";
File videoFile = new File(Environment.getExternalStorageDirectory() + "/media", videoPath);
try {
videoFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
Uri providerUri = FileContentProvider.CONTENT_URI.buildUpon().appendPath("media/" + videoPath).build();
mCurrentCameraUri = Uri.fromFile(videoFile);
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, providerUri);
takeVideoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
List<ResolveInfo> resInfoList = MainActivity.this.getPackageManager().queryIntentActivities(takeVideoIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resInfo : resInfoList) {
String packageName = resInfo.activityInfo.packageName;
MainActivity.this.grantUriPermission(packageName, providerUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}
清单文件提供者代码是
<provider
android:name=".adapters.contentprovider.FileContentProvider"
android:authorities="com.example.fileprovider"
android:exported="true"
android:grantUriPermissions="true">
<meta-data
android:name="com.example.FileContentProvider.STREAM_PROVIDER_PATHS"
android:resource="@xml/paths"/>
</provider>
xml路径是
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="media" path=""/>
</paths>
有人可以建议这个设备出了什么问题。