Last active
December 25, 2015 06:29
-
-
Save dzwillpower/6932158 to your computer and use it in GitHub Desktop.
扫描外接设备
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public HashMap<String, List<MusicInfo>> scanDirectory(File path, HashMap<String, List<MusicInfo>> musicHashMap) { | |
if (musicHashMap == null) { | |
musicHashMap = new HashMap<String, List<MusicInfo>>(); | |
} | |
if (path.exists()) { | |
File[] files = path.listFiles(); | |
if (files == null) { | |
return null; | |
} | |
for (int i = 0; i < files.length; i++) { | |
if (files[i].isDirectory()) { | |
scanDirectory(files[i], musicHashMap); | |
} else { | |
String extension = FileUtils.getExtension(files[i].getName()); | |
String mimeTypeString = null; | |
try { | |
if (!TextUtils.isEmpty(extension)) { | |
mimeTypeString = MimeTypeMap.getSingleton() | |
.getMimeTypeFromExtension(extension.substring(1)); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
if (mimeTypeString != null && mimeTypeString.startsWith("audio")) { | |
MediaMetadataRetriever mmr = new MediaMetadataRetriever(); | |
mmr.setDataSource(files[i].getAbsolutePath()); | |
MusicInfo musicInfo = new MusicInfo(); | |
musicInfo.setDisPlayName(files[i].getName()); | |
musicInfo.setData(files[i].getAbsolutePath()); | |
musicInfo.setMimeType(mimeTypeString); | |
musicInfo.setMusicArtist(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)); | |
musicInfo.setDuration(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)); | |
musicInfo.setMusicAlbum(mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM)); | |
if(musicInfo.getMusicAlbum()==null){ | |
continue; | |
} | |
if(musicHashMap.get(musicInfo.getMusicAlbum())==null){ | |
musicHashMap.put(musicInfo.getMusicAlbum(), new ArrayList<MusicInfo>()); | |
albumNames.add(musicInfo.getMusicAlbum()); | |
} | |
// MyLogger.dLog().e("***********> "+musicInfo.getDisPlayName()+"***********"+musicInfo.getMusicAlbum()); | |
musicHashMap.get(musicInfo.getMusicAlbum()).add(musicInfo); | |
} | |
} | |
} | |
} | |
return musicHashMap; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public HashMap<String, List<PictureInfo>> scanDirectory(File path, HashMap<String, List<PictureInfo>> pictureHashMap) { | |
if (pictureHashMap == null) { | |
pictureHashMap = new HashMap<String, List<PictureInfo>>(); | |
} | |
if (path.exists()) { | |
List<PictureInfo> mPicFile = new ArrayList<PictureInfo>(); | |
File[] files = path.listFiles(); | |
if (files == null) { | |
return null; | |
} | |
for (int i = 0; i < files.length; i++) { | |
if (files[i].isDirectory()) { | |
scanDirectory(files[i], pictureHashMap); | |
} else { | |
String extension = FileUtils.getExtension(files[i].getName()); | |
String mimeTypeString = null; | |
try { | |
if (!TextUtils.isEmpty(extension)) { | |
mimeTypeString = MimeTypeMap.getSingleton() | |
.getMimeTypeFromExtension(extension.substring(1)); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
if (mimeTypeString != null && mimeTypeString.startsWith("image")) { | |
PictureInfo pictureInfo = new PictureInfo(); | |
pictureInfo.setDisPlayName(files[i].getName()); | |
pictureInfo.setFilePath(files[i].getAbsolutePath()); | |
pictureInfo.setMimeType(mimeTypeString); | |
mPicFile.add(pictureInfo); | |
allPicturePaths.add(files[i].getAbsolutePath()); | |
} | |
} | |
} | |
if (mPicFile.size() > 0) { | |
folderNames.add(path.getPath()); | |
pictureHashMap.put(path.getPath(), mPicFile); | |
} | |
} | |
return pictureHashMap; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public HashMap<String, List<VideoInfo>> scanDirectory(File path,HashMap<String, List<VideoInfo>> videoHashMap) { | |
if(videoHashMap==null){ | |
videoHashMap= new HashMap<String, List<VideoInfo>>(); | |
} | |
if( path.exists() ) { | |
List<VideoInfo> mVideoFile=new ArrayList<VideoInfo>(); | |
File[] files = path.listFiles(); | |
if (files == null) { | |
return null; | |
} | |
for(int i=0; i<files.length; i++) { | |
if(files[i].isDirectory()) { | |
scanDirectory(files[i],videoHashMap); | |
} | |
else { | |
String extension = FileUtils.getExtension(files[i].getName()); | |
String mimeTypeString = null; | |
try { | |
if(!TextUtils.isEmpty(extension)){ | |
mimeTypeString = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.substring(1)); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
if( mimeTypeString !=null && mimeTypeString.startsWith("video")){ | |
VideoInfo videoInfo = new VideoInfo(); | |
videoInfo.setDisPlayName(files[i].getName()); | |
videoInfo.setFilePath(files[i].getAbsolutePath()); | |
videoInfo.setMimeType(mimeTypeString); | |
videoInfo.setData(files[i].getAbsolutePath()); | |
mVideoFile.add(videoInfo); | |
} | |
} | |
} | |
if(mVideoFile.size()>0){ | |
folderNames.add(path.getPath()); | |
videoHashMap.put(path.getPath(), mVideoFile); | |
} | |
} | |
return videoHashMap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment