diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-02-04 20:32:34 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-02-04 20:32:34 -0800 |
commit | 4fdaa88b473a210472b638995608a0a2c9f6ac15 (patch) | |
tree | 68d5ceb0a937fe7e893d00bfad5f82c873a131f1 /subsonic-android/src/github | |
parent | f5c51b8a982228ad3bfd7b0fd4b8748fd63caf6f (diff) | |
download | dsub-4fdaa88b473a210472b638995608a0a2c9f6ac15.tar.gz dsub-4fdaa88b473a210472b638995608a0a2c9f6ac15.tar.bz2 dsub-4fdaa88b473a210472b638995608a0a2c9f6ac15.zip |
Closes #101 Move metadata loading to after entry creation
Diffstat (limited to 'subsonic-android/src/github')
3 files changed, 28 insertions, 14 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java index c601c569..938bf624 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java @@ -518,6 +518,12 @@ public class SubsonicTabActivity extends SherlockActivity { bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000;
format = FileUtil.getExtension(file.getName());
size = file.length();
+
+ if(Util.isOffline(SubsonicTabActivity.this)) {
+ song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE));
+ String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
+ song.setYear(Integer.parseInt((year != null) ? year : "0"));
+ }
}
} catch(Exception e) {
Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver");
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java index 8d1cb307..4fbbaf2d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -153,20 +153,6 @@ public class OfflineMusicService extends RESTMusicService { entry.setArtist(file.getParentFile().getParentFile().getName()); entry.setAlbum(file.getParentFile().getName()); - try { - MediaMetadataRetriever metadata = new MediaMetadataRetriever(); - metadata.setDataSource(file.getAbsolutePath()); - entry.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE)); - String bitrate = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE); - entry.setBitRate(Integer.parseInt((bitrate != null) ? bitrate : "0") / 1000); - String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR); - entry.setYear(Integer.parseInt((year != null) ? year : "0")); - String length = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); - entry.setDuration(Integer.parseInt(length) / 1000); - } catch(Exception e) { - Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver"); - } - int index = name.indexOf('-'); if(index != -1) { try { diff --git a/subsonic-android/src/github/daneren2005/dsub/view/SongView.java b/subsonic-android/src/github/daneren2005/dsub/view/SongView.java index 1042546a..7cefae23 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/SongView.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/SongView.java @@ -19,6 +19,8 @@ package github.daneren2005.dsub.view; import android.content.Context; +import android.media.MediaMetadataRetriever; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.*; @@ -40,6 +42,7 @@ import java.io.File; public class SongView extends UpdateView implements Checkable { private static final String TAG = SongView.class.getSimpleName(); + private Context context; private MusicDirectory.Entry song; private CheckedTextView checkedTextView; @@ -52,6 +55,7 @@ public class SongView extends UpdateView implements Checkable { public SongView(Context context) { super(context); + this.context = context; LayoutInflater.from(context).inflate(R.layout.song_list_item, this, true); checkedTextView = (CheckedTextView) findViewById(R.id.song_check); @@ -64,6 +68,24 @@ public class SongView extends UpdateView implements Checkable { public void setSong(MusicDirectory.Entry song, boolean checkable) { this.song = song; + + if(Util.isOffline(context)) { + DownloadFile downloadFile = new DownloadFile(context, song, false); + File file = downloadFile.getCompleteFile(); + if(file.exists()) { + try { + MediaMetadataRetriever metadata = new MediaMetadataRetriever(); + metadata.setDataSource(file.getAbsolutePath()); + String bitrate = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE); + song.setBitRate(Integer.parseInt((bitrate != null) ? bitrate : "0") / 1000); + String length = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); + song.setDuration(Integer.parseInt(length) / 1000); + } catch(Exception e) { + Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver"); + } + } + } + StringBuilder artist = new StringBuilder(40); String bitRate = null; |