Question

I have an app(android) which must list all the recorded audios that created by my app and there are on this path :Dir_recorded_audios means this: /mnt/sdcard/My Audios/ I need to some details like DURATION of the audios. what is it problem? Too, I read these links:

Construct MediaStore URI for specific folder

Empty cursor from the MediaStore

Get all audio files from a folder

but I am so confused. this nesseray for me to know problem and correct solveing. in here is my full code:

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();
     }
}
Was it helpful?

Solution

This code was correct. Problem was:When i added an audio by recording to my folder must be refresh mediaStore.I find this code and before listing i call it.

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top