0

I have a tab in my app where I list all the songs available . However , I get complaints from few users that some of the songs which are visible in File Manager are not getting displayed . This is the cursor query I use

public static Cursor getAllSongsCursor(Context mContext){

    String selection= MediaStore.Audio.Media.DURATION + " >=" + minTimeSongLimit;

    String sortBy = SortArgFactory.getSortBy(FactoryConstants.TRACKS);


    Cursor cursor = mContext.getApplicationContext().getContentResolver().query(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            null,
            selection,
            null,
            sortBy);
    return cursor;
}

I am not able to figure out why this cursor query does not display all the songs which matches the selection condition.

Any help will be much appreciated .

( I have tried giving multiple patches to different customers but almost always they dont follow up and its working perfectly in all our test scenarios )

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
  • Also, in some of the cases , its definitely not indexing problem . There are users who complain half the music within a same folder is not displayed . – thenoob100pi Dec 18 '18 at 11:16
  • Be aware that .wma tracks will be ignored by android so these will not be found in the media database – Theo Dec 18 '18 at 16:46

1 Answers1

0

The mediaDatabase you are querying at that moment might not be refreshed(updated), because of which you cannot see the requested media.

You can trigger the refresh media. Kindly have look at the question below.

How can I refresh MediaStore on Android?

Snippet code from the above question

MediaScannerConnection.scanFile(
    context, 
    new String[]{ pathToFile1, pathToFile2 }, 
    new String[]{ "audio/mp3", "*/*" }, 
    new MediaScannerConnectionClient()
    {
        public void onMediaScannerConnected()
        {
        }
        public void onScanCompleted(String path, Uri uri)
        {
        }
    });
udit7395
  • 626
  • 5
  • 16
  • All the music is within same base folder . I dont think its an indexing / refresh issue – thenoob100pi Dec 18 '18 at 11:24
  • Can you give it a try once? If doesn't work let me know then – udit7395 Dec 18 '18 at 11:28
  • This is manually triggering a scan of a specific file right ? My problem is , users just complaining that few songs are missed. I dont have references to specific files which are missed to trigger a rescan . For ex : one particular user, the above query returned 5100 entries while he had 30000+ songs . Also , this query works perfectly fine in all our test cases in all our local test lab . – thenoob100pi Dec 18 '18 at 11:34
  • I think I might have confused you a bit. What I meant to say was lets say for example your user opens the app, every time your user opens the app trigger a media refresh, so you query from an up-to-date media database. I hope this helps. – udit7395 Dec 19 '18 at 08:28