How to get a selection of tracks using the duration range

71 Views Asked by At

I am trying to select tracks using duration ranges. for instance

String start = null;
String end = null;
if (criteria == getString(R.string.uptofivemins)) {
    start = "0";
    end = "300000";
}
String[] crit =  {start,end};
String where = "duration >= ? AND duration < ? ";
//.... 


private final Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
private final String duration = MediaStore.Audio.Media.DURATION;
//etc...
cr.query(uri, columns, where, crit, null);

Problem appears to be that as I need to feed in Strings start and end, the resulting query will execute using these. The database field "duration" however is of type int and from the results that are returned I suspects that the comparison is against strings rather than int so the selection is incorrect. Anyone with ideas on how to select tracks using duration ranges eg < 5 mins, between 5 and 10 mins, etc. Any help greatly appreciated.

1

There are 1 best solutions below

0
Theo On

Problem was sorted. A combination of human error and impatience. Query executes against the audio table

   SELECT duration FROM audio WHERE duration >= '300000' AND duration <= '600000';