I'm making a music player & here is the scenario:
I deleted a song from the directory which is in the current playlist and is about to be get played.(i.e. the song actually no longer exist in the phone)
But when player tries to play the song, it throws an error, catches it and plays the next song. Simple & it is working.
However the problem is:
I upload the deleted song in the phone again on its previous place.
But when I try to access it using Android database curson using MediaStore.Audio
, it still thinks that the song does not exist and throw the same error.
Below code is throwing android.database.CursorIndexOutOfBoundsException
Please suggest what to do?
Do I need to update some flags through which my application takes updated state of phone memory and able to get the song, or any thing else?
String quesryString = MediaStore.Audio.Media.IS_MUSIC + "!=" + 0 + " AND "
+ MediaStore.Audio.Media.DATA + " = \"" + trackData + "\"";
// trackData is the name of the mp3 file & is coming right
String[] projection = { MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.DURATION };
Cursor cursor = context.getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection,
quesryString, null, null);
cursor.moveToFirst();
String songTitle = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));