implement startNativeLibraryScan()
This commit is contained in:
parent
5782e295eb
commit
4ed4cd0fab
@ -66,6 +66,7 @@ public class MediaLibrary {
|
||||
sBackend = new MediaLibraryBackend(context);
|
||||
|
||||
sScanner = new MediaScanner(sBackend);
|
||||
sScanner.startNativeLibraryScan(context);
|
||||
sScanner.startUpdateScan();
|
||||
for (File dir : discoverMediaPaths()) {
|
||||
sScanner.startFullScan(dir);
|
||||
|
@ -18,10 +18,12 @@
|
||||
package ch.blinkenlights.android.medialibrary;
|
||||
|
||||
import ch.blinkenlights.bastp.Bastp;
|
||||
import android.content.Context;
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import android.util.Log;
|
||||
import android.provider.MediaStore;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Message;
|
||||
@ -78,6 +80,8 @@ public class MediaScanner implements Handler.Callback {
|
||||
/**
|
||||
* Performs a full check of the current media library, scanning for
|
||||
* removed or changed files
|
||||
*
|
||||
* @param context the context to use
|
||||
*/
|
||||
void startUpdateScan() {
|
||||
Cursor cursor = mBackend.query(false, MediaLibrary.TABLE_SONGS, new String[]{MediaLibrary.SongColumns.PATH}, null, null, null, null, null, null);
|
||||
@ -85,6 +89,17 @@ public class MediaScanner implements Handler.Callback {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_LIBRARY, 0, 0, cursor));
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries all items found in androids native media database
|
||||
*/
|
||||
void startNativeLibraryScan(Context context) {
|
||||
String selection = MediaStore.Audio.Media.IS_MUSIC + "!= 0";
|
||||
String[] projection = { MediaStore.MediaColumns.DATA };
|
||||
Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null);
|
||||
if (cursor != null)
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_LIBRARY, 0, 0, cursor));
|
||||
}
|
||||
|
||||
private static final int MSG_SCAN_DIRECTORY = 1;
|
||||
private static final int MSG_ADD_FILE = 2;
|
||||
private static final int MSG_UPDATE_LIBRARY = 3;
|
||||
@ -117,9 +132,12 @@ public class MediaScanner implements Handler.Callback {
|
||||
case MSG_UPDATE_LIBRARY: {
|
||||
Cursor cursor = (Cursor)message.obj;
|
||||
while (cursor.moveToNext()) {
|
||||
File update = new File(cursor.getString(0));
|
||||
String path = cursor.getString(0);
|
||||
if (path != null) {
|
||||
File update = new File(path);
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_FILE, 0, 0, update));
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user