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