Esempio n. 1
0
 private void addSongToList(File file) {
   if (file.getName().endsWith(".mp3")) {
     DatabaseHandler db = new DatabaseHandler(Setting.this);
     String songName = file.getName().substring(0, (file.getName().length() - 4));
     String songPath = file.getPath();
     MediaMetadataRetriever media = new MediaMetadataRetriever();
     media.setDataSource(songPath);
     byte[] data = media.getEmbeddedPicture();
     String songArtist = media.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
     String songAlbum = media.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
     media.release();
     db.addSongData(new SongData(songName, songPath, songArtist, songAlbum, data, 0));
     db.close();
   }
 }
Esempio n. 2
0
 private void scanDirectory(File directory, String type) {
   if (directory != null) {
     File[] listFiles = directory.listFiles();
     if (listFiles != null && listFiles.length > 0) {
       for (File file : listFiles) {
         if (file.isDirectory()) {
           scanDirectory(file, type);
         } else {
           if (type == RESET_TYPE) {
             addSongToList(file);
           } else {
             DatabaseHandler db = new DatabaseHandler(Setting.this);
             if (file.getName().endsWith(".mp3")) {
               if (db.checkSongPath(file.getPath())) {
                 Log.e("name update", file.getName());
                 addSongToList(file);
               }
             }
           }
         }
       }
     }
   }
 }