以下代码中的最后一行,我将FileDescriptor设置为MediaMetadataRetriever的数据源会抛出IllegalArgumentException(MediaMetadataRetrieverJNI:无效的文件描述符。)
ContentResolver resolver = getActivity().getBaseContext().getContentResolver();
final ParcelFileDescriptor parcelFileDescriptor;
try {
Uri uri = Uri.fromFile(new File(videoPath));
parcelFileDescriptor = resolver.openFileDescriptor(uri, "r");
} catch (FileNotFoundException e) {
Log.w("Could not open '" + videoPath + "'", e);
Toast.makeText(getActivity(), "File not found.", Toast.LENGTH_LONG).show();
return;
}
FileDescriptor fileDescriptor = null;
if (parcelFileDescriptor != null) {
fileDescriptor = parcelFileDescriptor.getFileDescriptor();
if(fileDescriptor == null)
Log.i(TAG, "fileDescriptor is null.");
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(mInputFileDescriptor);
知道导致FileDescriptor无效的原因吗? 感谢。