android - How to find files quickly? -


i need please!

i want make mp3 player on android , therefore need find mp3 files in storage.

so search them recursively in mp3 method:

private void getmp3files(context context, string directory,arraylist<musiclistarray> mp3_list){  mediametadataretriever mediametadataretriever = new mediametadataretriever(); uri uri; byte[] album_art; bitmap bitmap; /*file[] files = directory.listfiles(new mp3filenamefilter()); files = directory.listfiles();*/  file folder = new file(directory); (file file : folder.listfiles()) {     if (file.isfile()) {         if (file.getname().endswith(".mp3") || file.getname().endswith(".mp3")) {             uri = uri.fromfile(file);             mediametadataretriever.setdatasource(context,uri);             string artist = mediametadataretriever.extractmetadata(mediametadataretriever.metadata_key_artist);             string title = file.getname();             album_art = mediametadataretriever.getembeddedpicture();             if(album_art != null){                 bitmap = bitmapfactory.decodebytearray(album_art, 0, album_art.length);             }else{                 bitmap = bitmapfactory.decoderesource(context.getresources(),r.drawable.ic_launcher);             }             if(bitmap == null){                 bitmap = bitmapfactory.decoderesource(context.getresources(),r.drawable.ic_launcher);             }             if (title.indexof(".") > 0)                 title = title.substring(0, title.lastindexof("."));             if(artist == null){                 artist = getstring(r.string.unknown_artist);             }              mp3_list.add(new musiclistarray(title,artist,file,bitmap));         }     }else if(file.isdirectory()){         getmp3files(context, file.getpath(), mp3_list);     } } collections.sort(mp3_list);  /*for(int i=0;i<files.length;i++){     mp3_list.add(new musiclistarray(files[i].getname(),"test",files[i])); }*/ //return mp3_list; 

}

this slow , needs 3 seconds everytime start app.

first question: how manage reduce taken time? second question: how save list in file , load it?

thanks in advance!

i suggest use sql database store metadata (including file location) of mp3s. should warn have no experience media on android though. basic idea:

1) first time use (or on manual sync in settings) full 3 second sync -> @ sharedpreferences store key indicating first time use app

2) store meta information in sql database.

3) make app read database faster, if table designed correctly. store things cover art, file location, artist, title etc. can add things number of times listened , stuff. in addition if wrap sql layer content provider can perform custom searches of music.

4) when app running, run background indexing service finds new music, corrects changes/deletes etc. android service

the benefits of app faster user, need load data once in foreground , provide lot more flexibility in terms of searching, song choice, custom data etc.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -