diff options
author | daneren2005 <daneren2005@gmail.com> | 2013-08-30 11:29:55 -0700 |
---|---|---|
committer | daneren2005 <daneren2005@gmail.com> | 2013-08-30 11:29:55 -0700 |
commit | 880e67c505338d7c969ce1fd95e6a086ac4cefdd (patch) | |
tree | c9ea967ace85e15cf7caa5d1e9431b6d1ce37622 /src | |
parent | aa548fcd3a40a5c9cd38da86fb289b98f1977a6d (diff) | |
download | dsub-880e67c505338d7c969ce1fd95e6a086ac4cefdd.tar.gz dsub-880e67c505338d7c969ce1fd95e6a086ac4cefdd.tar.bz2 dsub-880e67c505338d7c969ce1fd95e6a086ac4cefdd.zip |
Add Entry.loadMetadata(File file) method
Diffstat (limited to 'src')
-rw-r--r-- | src/github/daneren2005/dsub/domain/MusicDirectory.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/github/daneren2005/dsub/domain/MusicDirectory.java b/src/github/daneren2005/dsub/domain/MusicDirectory.java index c05d1631..90bb4c50 100644 --- a/src/github/daneren2005/dsub/domain/MusicDirectory.java +++ b/src/github/daneren2005/dsub/domain/MusicDirectory.java @@ -18,9 +18,11 @@ */ package github.daneren2005.dsub.domain; +import android.media.MediaMetadataRetriever; import android.util.Log; import java.util.ArrayList; import java.util.List; +import java.io.File; import java.io.Serializable; import java.util.Collections; import java.util.Comparator; @@ -121,6 +123,37 @@ public class MusicDirectory { private Integer discNumber; private boolean starred; private int closeness; + + public void loadMetadata(File file) { + try { + MediaMetadataRetriever metadata = new MediaMetadataRetriever(); + metadata.setDataSource(file.getAbsolutePath()); + String discNumber = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DISC_NUMBER); + if(discNumber == null) { + discNumber = "1/1"; + } + int slashIndex = discNumber.indexOf("/"); + if(slashIndex > 0) { + discNumber = discNumber.substring(0, slashIndex); + } + setDiscNumber(Integer.parseInt(discNumber)); + String bitrate = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE); + setBitRate(Integer.parseInt((bitrate != null) ? bitrate : "0") / 1000); + String length = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); + setDuration(Integer.parseInt(length) / 1000); + String artist = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); + if(artist != null) { + setArtist(artist); + } + String album = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM); + if(album != null) { + setAlbum(album); + } + metadata.release(); + } catch(Exception e) { + Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver"); + } + } public String getId() { return id; |