我有一个应用程序(android),必须列出我的应用程序创建的所有录制的音频,并且在此路径上:Dir_recorded_audios表示:/ mnt / sdcard / My Audios / 我需要一些细节,如音频的DURATION。这是什么问题? 我也读过这些链接:
Construct MediaStore URI for specific folder
Empty cursor from the MediaStore
Get all audio files from a folder
但是我很困惑。这个nesseray让我知道问题并正确解决。 在这里是我的完整代码:public static void getAllRecordedAudios(Context context)
{
String name="";
String format="";
String path="";
String size="";
String totalTime="";
String createTime="";
String createDate="";
String[] star={"*"};
Cursor audioCursor = ((Activity)context ). managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,star, null, null, null);
if (audioCursor==null)
Log.d("audio cursor is null","");
if (audioCursor != null)
{
if (audioCursor.moveToFirst())
{
do
{
String path = audioCursor.getString(audioCursor.getColumnIndex(MediaStore.Audio.Media.DATA));
name=audioCursor.getString(audioCursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
String str_duration=audioCursor.getString(audioCursor.getColumnIndex(MediaStore.Audio.Media.DURATION));
totalTime=SDcard.CalTotalTime(Integer.valueOf(str_duration));
String last =audioCursor.getString(audioCursor.getColumnIndex(MediaStore.Audio.Media.DATE_MODIFIED));
createDate=last;
size=audioCursor.getString(audioCursor.getColumnIndex(MediaStore.Audio.Media.SIZE));
format=SDcard.getFormat(current_path);
Log.d("************", "**************");
Log.d("name", name);
Log.d("format", format);
Log.d("path",path);
Log.d("totalTime", totalTime);
Log.d("size", size);
Log.d("createTime", createTime);
Log.d("createdate", createDate);
StructureDetails audioDetails=new StructureDetails( name, format, path,totalTime , size , createTime , createDate);
ArrayManager.Add_ThisAudio_ToArrayRecorded(audioDetails);
}while (audioCursor.moveToNext());
}
audioCursor.close();
}
}
答案 0 :(得分:0)
此代码是正确的。问题是:当我通过录制到我的文件夹添加音频时必须刷新mediaStore.I找到这段代码并在列出之前我调用它。
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));