ビデオサムネイル用のビデオファイルのパスを取得しようとしています。ここでいくつかの解決策に基づいて修正した後もなぜそれがまだnullになっているのか分かりません。アンドロイドのバージョンは6.0.1です。メディアストアからのAndroidビデオファイルのパスがnullになる
ユーザはフローティングアクションボタンをクリックし、ビデオギャラリーを呼び出す。
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.addNote);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Video"), REQUEST_TAKE_GALLERY_VIDEO);
}
});
ユーザーがギャラリーから目的のビデオを選択すると、ビデオはソートされるアクティビティに移動します。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
Log.d(TAG, "Uri: " + uri);
Log.d(TAG, "Uri authority: " + uri.getAuthority());
String filemanagerstring = uri.getPath();
Log.d(TAG, "filemanagerstring: " + filemanagerstring);
String selectedImagePath = getPath(uri);
Log.d(TAG, "selectedImagePath: " + selectedImagePath);
}
}
ビデオファイルのパスを取得する方法。
public String getPath(Uri uri) {
Cursor cursor = this.getContentResolver().query(uri, null, null, null, null);
int idx = 0;
//Source not from device capture or selection
if (cursor == null) {
return uri.getPath();
} else {
cursor.moveToFirst();
idx = cursor.getColumnIndex(MediaStore.Video.VideoColumns.DATA);
if (idx == -1) {
Log.d(TAG, "uri path: " + path);
return uri.getPath();
}
}
String path = cursor.getString(idx);
Log.d(TAG, "path: " + path);
cursor.close();
return path;
}
結果:私はnull(-1)を取得し、正しいパスではない、uriのパスを取得しました。ビデオファイルの完全なパスが必要です。
Uri: content://com.android.providers.media.documents/document/video%3A6174
Uri authority: com.android.providers.media.documents
filemanagerstring: /document/video:6174
**uri path: 16842794**
selectedImagePath: /document/video:6174
「私はフルを必要としますビデオファイルのパス " - いいえ、ビデオのサムネイルが必要です。ファイルシステムにアクセスできるファイルはもちろんのこと、ファイルがなくてもかまいませんので、「フルパス」である必要はありません。この「ウリ」はどこから来たのですか? – CommonsWare
uriはUriから来ていますuri = data.getData(); onActivityResultに格納されます。ユーザーがギャラリーからビデオを選択します(これが知りたい場合)。迅速な返信をありがとう! – Meep
この 'onActivityResult()'呼び出しをトリガーしている 'startActivityForResult()'呼び出しは何ですか? – CommonsWare