我想阻止我的音乐播放器应用程序在每次应用程序启动时扫描目录中的音频文件.我怎样才能做到这一点?
public void getSongList() { ContentResolver contentResolver=getContentResolver(); Uri musicUri=android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; Cursor musicCursor = contentResolver.query(musicUri,null,null); if(musicCursor!=null && musicCursor.moveToFirst()) { //get columns int titleColumn = musicCursor.getColumnIndex (android.provider.MediaStore.Audio.Media.TITLE); int idColumn = musicCursor.getColumnIndex (android.provider.MediaStore.Audio.Media._ID); int artistColumn = musicCursor.getColumnIndex (android.provider.MediaStore.Audio.Media.ARTIST); int albumIDColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID); //add songs to list do { long thisId = musicCursor.getLong(idColumn); String thisTitle = musicCursor.getString(titleColumn); String thisArtist = musicCursor.getString(artistColumn); long thisAlbumID=musicCursor.getLong(albumIDColumn); Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart"); Bitmap albumArtBitMap=null; Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri,thisAlbumID); try { albumArtBitMap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),albumArtUri); Matrix m = new Matrix(); m.setRectToRect(new RectF(0,albumArtBitMap.getWidth(),albumArtBitMap.getHeight()),new RectF(0,300,300),Matrix.ScaleToFit.CENTER); albumArtBitMap = Bitmap.createBitmap(albumArtBitMap,albumArtBitMap.getHeight(),m,true); } catch (IOException e) { e.printStackTrace(); } songList.add(new Song(thisId,thisTitle,thisArtist,albumArtBitMap)); } while (musicCursor.moveToNext()); } }
我希望应用程序只在有新文件时进行扫描.因为如果我每次都扫描整张SD卡,那么启动应用程序需要花费太多时间.请帮帮我