How Can I Get The Audio File That The User Picks
I would want to get a handle to the actual audio file that i pick. For selecting the audio file, i have an intent that looks like this : Intent audioIntent = new Intent(Intent.ACTI
Solution 1:
IntentgalleryIntent=newIntent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, AUDIO_GALLERY_REQUEST_CODE);
if (requestCode == AUDIO_GALLERY_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
try {
Stringpath= _getRealPathFromURI(context, intent.getData());
Fileaudio=newFile(path);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private String _getRealPathFromURI(Context context, Uri contentUri) {
String[] proj = { MediaStore.Audio.Media.DATA };
CursorLoaderloader=newCursorLoader(context, contentUri, proj, null, null, null);
Cursorcursor= loader.loadInBackground();
intcolumn_index= cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
Solution 2:
There should be a similar method for android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
, it has a getContentUri(String)
that returns a Uri
object. See if that helps.
Post a Comment for "How Can I Get The Audio File That The User Picks"