作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想从图库中获取视频,但我遇到显示手机一般内存的问题,如何解决?
private void selectVideo()
{
Intent i = new Intent(this, FastScrollerFilePickerActivity.class);
i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false);
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE);
String searchFolder;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String fileSearchPath = prefs.getString("fileSearchPath", "last-used");
switch(fileSearchPath)
{
case "last-used":
default:
prefs = getSharedPreferences(SHARED_PREFS_KEY, MODE_PRIVATE);
searchFolder = prefs.getString(PICKER_DIR_PREF, Environment.getExternalStorageDirectory().getPath());
break;
case "external":
searchFolder = Environment.getExternalStorageDirectory().getPath();
break;
}
i.putExtra(FilePickerActivity.EXTRA_START_PATH, searchFolder);
startActivityForResult(i, SELECT_FILE_REQUEST);
}
我想从图库中获取视频,但我遇到显示手机一般内存的问题,如何解决?
protected AbstractFilePickerFragment getFragment(@Nullable String startPath, int mode, boolean allowMultiple, boolean allowCreateDir, boolean allowExistingFile, boolean singleClick)
{
return getFragment(startPath, mode, allowMultiple, allowCreateDir);
}
protected AbstractFilePickerFragment<File> getFragment(
@Nullable final String startPath, final int mode, final boolean allowMultiple,
final boolean allowCreateDir) {
AbstractFilePickerFragment<File> fragment = new FastScrollerFilePickerFragment();
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
fragment.setArgs(startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath(),
mode, allowMultiple, allowCreateDir, true, false);
return fragment;
}
最佳答案
您可以使用以下行启动视频选择器
startActivityForResult(new Intent(Intent.ACTION_PICK,MediaStore.Video.Media.EXTERNAL_CONTENT_URI),
SELECT_FILE_REQUEST_CODE);
如果您的应用程序崩溃,它必须在 Logcat
中留下红色消息,这对于尝试让您理解问题非常有帮助。
现在,在您的 onActivityResult
方法中输入以下内容以获取您选择的视频的路径:
public void onActivityResult(int reqCode, int resCode, Intent data){
if(reqCode == SELECT_FILE_REQUEST_CODE){
Uri selectedVideo = data.getData();
String[] filePathColumn = { MediaStore.Video.Media.DATA };
Cursor cursor = getContentResolver().query(selectedVideo,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String videoPath = cursor.getString(columnIndex);
cursor.close();
}
}
关于java - FilePickerActivity.EXTRA_MODE、FilePickerActivity.MODE_FILE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59328018/
我想从图库中获取视频,但我遇到显示手机一般内存的问题,如何解决? private void selectVideo() { Intent i = new Intent(this, FastS
我是一名优秀的程序员,十分优秀!