diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-10-14 15:48:27 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-10-14 15:48:27 -0700 |
commit | cfa5d8da1ae4a70112d7b4ee0d2e7257e3e2d4d0 (patch) | |
tree | 5dd377a8e5aba0766aa493f0dde825ca85f5154a /src | |
parent | ef4588a6950c0b64c5ceb3fe46782f4785b1cd94 (diff) | |
download | dsub-cfa5d8da1ae4a70112d7b4ee0d2e7257e3e2d4d0.tar.gz dsub-cfa5d8da1ae4a70112d7b4ee0d2e7257e3e2d4d0.tar.bz2 dsub-cfa5d8da1ae4a70112d7b4ee0d2e7257e3e2d4d0.zip |
Change bitrate to be calculated on the fly instead of reading tags (fix for VBR)
Diffstat (limited to 'src')
-rw-r--r-- | src/github/daneren2005/dsub/fragments/SubsonicFragment.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 70a3b027..9ecaa0e9 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -1178,6 +1178,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR }
public void displaySongInfo(final Entry song) {
+ Integer duration = null;
Integer bitrate = null;
String format = null;
long size = 0;
@@ -1188,10 +1189,21 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR if(file.exists()) {
MediaMetadataRetriever metadata = new MediaMetadataRetriever();
metadata.setDataSource(file.getAbsolutePath());
- String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);
- bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000;
+
+ String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
+ duration = Integer.parseInt((tmp != null) ? tmp : "0") / 1000;
format = FileUtil.getExtension(file.getName());
size = file.length();
+
+ // If no duration try to read bitrate tag
+ if(duration == null) {
+ tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);
+ bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000;
+ } else {
+ // Otherwise do a calculation for it
+ // Divide by 1000 so in kbps
+ bitrate = (size / duration) / 1000;
+ }
if(Util.isOffline(context)) {
song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE));
|